import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';

import { WarehouseInventory } from './warehouse-inventory.entity';

@Entity({ schema: 'freight', name: 'warehouse_inventory_movement' })
@Index(['inventoryId'])
export class WarehouseInventoryMovement extends BaseEntity {
  @Column({ name: 'inventory_id', type: 'uuid' })
  inventoryId!: string;

  @ManyToOne(() => WarehouseInventory, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'inventory_id' })
  inventory?: WarehouseInventory;

  @Column({ name: 'from_warehouse_id', type: 'uuid' })
  fromWarehouseId!: string;

  @Column({ name: 'from_yard_id', type: 'uuid' })
  fromYardId!: string;

  @Column({ name: 'from_zone_id', type: 'uuid' })
  fromZoneId!: string;

  @Column({ name: 'to_warehouse_id', type: 'uuid' })
  toWarehouseId!: string;

  @Column({ name: 'to_yard_id', type: 'uuid' })
  toYardId!: string;

  @Column({ name: 'to_zone_id', type: 'uuid' })
  toZoneId!: string;

  @Column({ name: 'remarks', type: 'text', nullable: true })
  remarks?: string | null;

  @Column({ name: 'moved_by', type: 'varchar', length: 120, nullable: true })
  movedBy?: string | null;

  @Column({ name: 'moved_at', type: 'timestamptz' })
  movedAt!: Date;
}
