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

export class CreateQuotationDto {
  @IsUUID() partnerId: string;
  @IsOptional() @IsString() @MaxLength(200) partnerName?: string;
  @IsOptional() @IsString() partnerEmail?: string;
  @IsOptional() @IsObject() billingAddress?: object;
  @IsOptional() @IsObject() shippingAddress?: object;
  @IsOptional() @IsDateString() quotationDate?: string;
  @IsOptional() @IsDateString() validUntil?: string;
  @IsOptional() @IsUUID() salesRepId?: string;
  @IsOptional() @IsString() @MaxLength(3) currency?: string;
  @IsOptional() @IsNumber() paymentTermDays?: number;
  @IsOptional() @IsString() paymentMethod?: string;
  @IsOptional() @IsString() notes?: string;
  @IsOptional() @IsString() termsAndConditions?: string;
  @IsOptional() @IsArray() items?: CreateQuotationItemDto[];
}

export class CreateQuotationItemDto {
  @IsOptional() @IsUUID() productId?: string;
  @IsString() @MaxLength(200) productName: string;
  @IsOptional() @IsString() @MaxLength(50) productSku?: string;
  @IsOptional() @IsString() description?: 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 UpdateQuotationDto {
  @IsOptional() @IsUUID() partnerId?: string;
  @IsOptional() @IsString() @MaxLength(200) partnerName?: string;
  @IsOptional() @IsObject() billingAddress?: object;
  @IsOptional() @IsObject() shippingAddress?: object;
  @IsOptional() @IsDateString() validUntil?: string;
  @IsOptional() @IsString() @MaxLength(3) currency?: string;
  @IsOptional() @IsNumber() paymentTermDays?: number;
  @IsOptional() @IsString() notes?: string;
  @IsOptional() @IsEnum(['draft', 'sent', 'accepted', 'rejected', 'expired']) status?: string;
}

export class CreateSalesOrderDto {
  @IsUUID() partnerId: string;
  @IsOptional() @IsString() @MaxLength(200) partnerName?: string;
  @IsOptional() @IsUUID() quotationId?: string;
  @IsOptional() @IsObject() billingAddress?: object;
  @IsOptional() @IsObject() shippingAddress?: object;
  @IsOptional() @IsDateString() requestedDate?: string;
  @IsOptional() @IsDateString() promisedDate?: string;
  @IsOptional() @IsUUID() salesRepId?: string;
  @IsOptional() @IsUUID() warehouseId?: string;
  @IsOptional() @IsString() @MaxLength(3) currency?: string;
  @IsOptional() @IsNumber() paymentTermDays?: number;
  @IsOptional() @IsString() paymentMethod?: string;
  @IsOptional() @IsString() shippingMethod?: string;
  @IsOptional() @IsString() notes?: string;
  @IsOptional() @IsArray() items?: CreateOrderItemDto[];
}

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

export class UpdateSalesOrderDto {
  @IsOptional() @IsObject() shippingAddress?: object;
  @IsOptional() @IsDateString() promisedDate?: string;
  @IsOptional() @IsString() shippingMethod?: string;
  @IsOptional() @IsString() trackingNumber?: string;
  @IsOptional() @IsString() carrier?: string;
  @IsOptional() @IsString() notes?: string;
  @IsOptional() @IsEnum(['draft', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled']) status?: string;
}
