import { IsString, IsOptional, IsNumber, IsUUID, IsDateString, IsArray, IsObject, MaxLength, IsEnum, Min } from 'class-validator';

export class CreatePurchaseOrderDto {
  @IsUUID() supplierId: string;
  @IsOptional() @IsString() @MaxLength(200) supplierName?: string;
  @IsOptional() @IsString() supplierEmail?: string;
  @IsOptional() @IsObject() shippingAddress?: object;
  @IsOptional() @IsDateString() expectedDate?: string;
  @IsOptional() @IsUUID() buyerId?: string;
  @IsOptional() @IsUUID() warehouseId?: string;
  @IsOptional() @IsString() @MaxLength(3) currency?: string;
  @IsOptional() @IsNumber() paymentTermDays?: number;
  @IsOptional() @IsString() paymentMethod?: string;
  @IsOptional() @IsString() @MaxLength(10) incoterm?: string;
  @IsOptional() @IsString() supplierReference?: string;
  @IsOptional() @IsString() notes?: string;
  @IsOptional() @IsArray() items?: CreatePurchaseItemDto[];
}

export class CreatePurchaseItemDto {
  @IsOptional() @IsUUID() productId?: string;
  @IsString() @MaxLength(200) productName: string;
  @IsOptional() @IsString() @MaxLength(50) productSku?: string;
  @IsOptional() @IsString() @MaxLength(50) supplierSku?: string;
  @IsNumber() @Min(0) quantity: number;
  @IsOptional() @IsString() @MaxLength(20) uom?: string;
  @IsNumber() @Min(0) unitPrice: number;
  @IsOptional() @IsNumber() discountPercent?: number;
  @IsOptional() @IsNumber() taxRate?: number;
}

export class UpdatePurchaseOrderDto {
  @IsOptional() @IsObject() shippingAddress?: object;
  @IsOptional() @IsDateString() expectedDate?: string;
  @IsOptional() @IsUUID() warehouseId?: string;
  @IsOptional() @IsString() supplierReference?: string;
  @IsOptional() @IsString() notes?: string;
  @IsOptional() @IsEnum(['draft', 'sent', 'confirmed', 'partial', 'received', 'cancelled']) status?: string;
}

// 3-Way Matching DTOs
export * from './matching-status.dto';
export * from './resolve-exception.dto';
