import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index, ManyToOne, JoinColumn } from 'typeorm';
import { TransferOrder } from './transfer-order.entity';

@Entity({ name: 'transfer_order_lines', schema: 'inventory' })
export class TransferOrderLine {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'transfer_id', type: 'uuid' })
  transferId: string;

  @ManyToOne(() => TransferOrder, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'transfer_id' })
  transfer: TransferOrder;

  @Index()
  @Column({ name: 'product_id', type: 'uuid' })
  productId: string;

  @Column({ name: 'source_location_id', type: 'uuid', nullable: true })
  sourceLocationId?: string;

  @Column({ name: 'dest_location_id', type: 'uuid', nullable: true })
  destLocationId?: string;

  @Column({ name: 'quantity_requested', type: 'decimal', precision: 15, scale: 4 })
  quantityRequested: number;

  @Column({ name: 'quantity_shipped', type: 'decimal', precision: 15, scale: 4, default: 0 })
  quantityShipped: number;

  @Column({ name: 'quantity_received', type: 'decimal', precision: 15, scale: 4, default: 0 })
  quantityReceived: number;

  @Column({ name: 'lot_number', type: 'varchar', length: 50, nullable: true })
  lotNumber?: string;

  @Column({ name: 'serial_number', type: 'varchar', length: 50, nullable: true })
  serialNumber?: string;

  @Column({ type: 'text', nullable: true })
  notes?: string;

  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt: Date;
}
