import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm';

@Entity({ name: 'purchase_receipts', schema: 'purchases' })
export class PurchaseReceipt {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'tenant_id', type: 'uuid' })
  tenantId: string;

  @Index()
  @Column({ name: 'order_id', type: 'uuid' })
  orderId: string;

  @Column({ name: 'receipt_number', type: 'varchar', length: 30 })
  receiptNumber: string;

  @Column({ name: 'receipt_date', type: 'date', default: () => 'CURRENT_DATE' })
  receiptDate: Date;

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

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

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

  @Column({ name: 'supplier_delivery_note', type: 'varchar', length: 100, nullable: true })
  supplierDeliveryNote?: string;

  @Column({ name: 'supplier_invoice_number', type: 'varchar', length: 100, nullable: true })
  supplierInvoiceNumber?: string;

  @Index()
  @Column({ type: 'varchar', length: 20, default: 'draft' })
  status: 'draft' | 'confirmed' | 'cancelled';

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

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

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

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