import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index, ManyToOne, JoinColumn } from 'typeorm';
import { Product } from './product.entity';

@Entity({ name: 'product_suppliers', schema: 'products' })
export class ProductSupplier {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

  @ManyToOne(() => Product, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'product_id' })
  product: Product;

  @Index()
  @Column({ name: 'supplier_id', type: 'uuid' })
  supplierId: string;

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

  @Column({ name: 'supplier_name', type: 'varchar', length: 200, nullable: true })
  supplierName?: string;

  @Column({ name: 'purchase_price', type: 'decimal', precision: 15, scale: 4, nullable: true })
  purchasePrice?: number;

  @Column({ type: 'varchar', length: 3, default: 'MXN' })
  currency: string;

  @Column({ name: 'min_order_qty', type: 'decimal', precision: 15, scale: 4, default: 1 })
  minOrderQty: number;

  @Column({ name: 'lead_time_days', type: 'int', default: 0 })
  leadTimeDays: number;

  @Index()
  @Column({ name: 'is_preferred', type: 'boolean', default: false })
  isPreferred: boolean;

  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive: boolean;

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

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