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

export class CreateStockMovementDto {
  @IsEnum(['receipt', 'shipment', 'transfer', 'adjustment', 'return', 'production', 'consumption'])
  movementType:
    | 'receipt'
    | 'shipment'
    | 'transfer'
    | 'adjustment'
    | 'return'
    | 'production'
    | 'consumption';

  @IsUUID()
  productId: string;

  @IsOptional()
  @IsUUID()
  sourceWarehouseId?: string;

  @IsOptional()
  @IsUUID()
  sourceLocationId?: string;

  @IsOptional()
  @IsUUID()
  destWarehouseId?: string;

  @IsOptional()
  @IsUUID()
  destLocationId?: string;

  @IsNumber()
  @Min(0)
  quantity: number;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  uom?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  lotNumber?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  serialNumber?: string;

  @IsOptional()
  @IsDateString()
  expiryDate?: string;

  @IsOptional()
  @IsNumber()
  @Min(0)
  unitCost?: number;

  @IsOptional()
  @IsString()
  @MaxLength(30)
  referenceType?: string;

  @IsOptional()
  @IsUUID()
  referenceId?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  referenceNumber?: string;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  reason?: string;

  @IsOptional()
  @IsString()
  notes?: string;
}

export class AdjustStockDto {
  @IsUUID()
  productId: string;

  @IsUUID()
  warehouseId: string;

  @IsOptional()
  @IsUUID()
  locationId?: string;

  @IsNumber()
  newQuantity: number;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  lotNumber?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  serialNumber?: string;

  @IsString()
  @MaxLength(100)
  reason: string;

  @IsOptional()
  @IsString()
  notes?: string;
}

export class TransferStockDto {
  @IsUUID()
  productId: string;

  @IsUUID()
  sourceWarehouseId: string;

  @IsOptional()
  @IsUUID()
  sourceLocationId?: string;

  @IsUUID()
  destWarehouseId: string;

  @IsOptional()
  @IsUUID()
  destLocationId?: string;

  @IsNumber()
  @Min(0)
  quantity: number;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  lotNumber?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  serialNumber?: string;

  @IsOptional()
  @IsString()
  notes?: string;
}

export class ReserveStockDto {
  @IsUUID()
  productId: string;

  @IsUUID()
  warehouseId: string;

  @IsOptional()
  @IsUUID()
  locationId?: string;

  @IsNumber()
  @Min(0)
  quantity: number;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  lotNumber?: string;

  @IsOptional()
  @IsString()
  @MaxLength(30)
  referenceType?: string;

  @IsOptional()
  @IsUUID()
  referenceId?: string;
}
