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

export class CreateWarehouseDto {
  @IsString()
  @MaxLength(20)
  code: string;

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

  @IsOptional()
  @IsString()
  description?: string;

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

  @IsOptional()
  @IsEnum(['standard', 'transit', 'returns', 'quarantine', 'virtual'])
  warehouseType?: 'standard' | 'transit' | 'returns' | 'quarantine' | 'virtual';

  @IsOptional()
  @IsString()
  @MaxLength(200)
  addressLine1?: string;

  @IsOptional()
  @IsString()
  @MaxLength(200)
  addressLine2?: string;

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

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

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

  @IsOptional()
  @IsString()
  @MaxLength(3)
  country?: string;

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

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

  @IsOptional()
  @IsString()
  @MaxLength(255)
  email?: string;

  @IsOptional()
  @IsNumber()
  latitude?: number;

  @IsOptional()
  @IsNumber()
  longitude?: number;

  @IsOptional()
  @IsNumber()
  capacityUnits?: number;

  @IsOptional()
  @IsNumber()
  capacityVolume?: number;

  @IsOptional()
  @IsNumber()
  capacityWeight?: number;

  @IsOptional()
  @IsObject()
  settings?: {
    allowNegative?: boolean;
    autoReorder?: boolean;
  };

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsBoolean()
  isDefault?: boolean;
}

export class UpdateWarehouseDto {
  @IsOptional()
  @IsString()
  @MaxLength(20)
  code?: string;

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

  @IsOptional()
  @IsString()
  description?: string;

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

  @IsOptional()
  @IsEnum(['standard', 'transit', 'returns', 'quarantine', 'virtual'])
  warehouseType?: 'standard' | 'transit' | 'returns' | 'quarantine' | 'virtual';

  @IsOptional()
  @IsString()
  @MaxLength(200)
  addressLine1?: string;

  @IsOptional()
  @IsString()
  @MaxLength(200)
  addressLine2?: string;

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

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

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

  @IsOptional()
  @IsString()
  @MaxLength(3)
  country?: string;

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

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

  @IsOptional()
  @IsString()
  @MaxLength(255)
  email?: string;

  @IsOptional()
  @IsNumber()
  latitude?: number;

  @IsOptional()
  @IsNumber()
  longitude?: number;

  @IsOptional()
  @IsNumber()
  capacityUnits?: number;

  @IsOptional()
  @IsNumber()
  capacityVolume?: number;

  @IsOptional()
  @IsNumber()
  capacityWeight?: number;

  @IsOptional()
  @IsObject()
  settings?: {
    allowNegative?: boolean;
    autoReorder?: boolean;
  };

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsBoolean()
  isDefault?: boolean;
}

export class CreateWarehouseLocationDto {
  @IsUUID()
  warehouseId: string;

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

  @IsString()
  @MaxLength(30)
  code: string;

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

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

  @IsOptional()
  @IsEnum(['zone', 'aisle', 'rack', 'shelf', 'bin'])
  locationType?: 'zone' | 'aisle' | 'rack' | 'shelf' | 'bin';

  @IsOptional()
  @IsString()
  @MaxLength(10)
  aisle?: string;

  @IsOptional()
  @IsString()
  @MaxLength(10)
  rack?: string;

  @IsOptional()
  @IsString()
  @MaxLength(10)
  shelf?: string;

  @IsOptional()
  @IsString()
  @MaxLength(10)
  bin?: string;

  @IsOptional()
  @IsNumber()
  capacityUnits?: number;

  @IsOptional()
  @IsNumber()
  capacityVolume?: number;

  @IsOptional()
  @IsNumber()
  capacityWeight?: number;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  allowedProductTypes?: string[];

  @IsOptional()
  @IsObject()
  temperatureRange?: { min?: number; max?: number };

  @IsOptional()
  @IsObject()
  humidityRange?: { min?: number; max?: number };

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsBoolean()
  isPickable?: boolean;

  @IsOptional()
  @IsBoolean()
  isReceivable?: boolean;
}

export class UpdateWarehouseLocationDto {
  @IsOptional()
  @IsString()
  @MaxLength(30)
  code?: string;

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

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

  @IsOptional()
  @IsEnum(['zone', 'aisle', 'rack', 'shelf', 'bin'])
  locationType?: 'zone' | 'aisle' | 'rack' | 'shelf' | 'bin';

  @IsOptional()
  @IsString()
  @MaxLength(10)
  aisle?: string;

  @IsOptional()
  @IsString()
  @MaxLength(10)
  rack?: string;

  @IsOptional()
  @IsString()
  @MaxLength(10)
  shelf?: string;

  @IsOptional()
  @IsString()
  @MaxLength(10)
  bin?: string;

  @IsOptional()
  @IsNumber()
  capacityUnits?: number;

  @IsOptional()
  @IsNumber()
  capacityVolume?: number;

  @IsOptional()
  @IsNumber()
  capacityWeight?: number;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  allowedProductTypes?: string[];

  @IsOptional()
  @IsObject()
  temperatureRange?: { min?: number; max?: number };

  @IsOptional()
  @IsObject()
  humidityRange?: { min?: number; max?: number };

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsBoolean()
  isPickable?: boolean;

  @IsOptional()
  @IsBoolean()
  isReceivable?: boolean;
}
