import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { GateEntity } from '../../domain/entities/gate.entity';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
import { GateType } from '../../constants';
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';

@Entity(TABLE_NAME.GATE)
export class GateModel
  extends BaseStatusModel<GateEntity>
  implements GateEntity
{
  @Column('enum', {
    name: 'type',
    enum: GateType,
    default: GateType.GATE_IN,
  })
  type: GateType;

  @Column('varchar', { name: 'code', nullable: true })
  code: string;

  @Column('text', { name: 'note', nullable: true })
  note: string;

  @Column('varchar', { name: 'item_id', nullable: true })
  item_id: string;
  @ManyToOne(() => ItemModel, (model) => model.gates, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  @JoinColumn({ name: 'item_id' })
  item: ItemModel;
}
