import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
import { IsEnum, IsInt, IsNumber, IsOptional, IsString, IsUUID, Min } from 'class-validator';

import { FEE_RULE_TYPES, FeeRuleType } from '../entities/warehouse-fee-rule.entity';

export class CreateFeeRuleDto {
  @ApiProperty()
  @IsString()
  name!: string;

  @ApiProperty({ enum: FEE_RULE_TYPES })
  @IsEnum(FEE_RULE_TYPES)
  ruleType!: FeeRuleType;

  @ApiPropertyOptional({ default: 100 })
  @IsOptional()
  @IsInt()
  priority?: number;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  freightType?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  tradeDirection?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  cargoTypeCode?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  containerType?: string;

  @ApiPropertyOptional({ format: 'uuid' })
  @IsOptional()
  @IsUUID()
  facilityId?: string;

  @ApiPropertyOptional({ format: 'uuid' })
  @IsOptional()
  @IsUUID()
  warehouseId?: string;

  @ApiPropertyOptional({ format: 'uuid' })
  @IsOptional()
  @IsUUID()
  yardId?: string;

  @ApiPropertyOptional({ format: 'uuid' })
  @IsOptional()
  @IsUUID()
  zoneId?: string;

  @ApiProperty({ description: 'Grace period in days before charging starts.' })
  @IsInt()
  @Min(0)
  freeDays!: number;

  @ApiProperty()
  @IsNumber()
  @Min(0)
  ratePerDay!: number;

  @ApiPropertyOptional({ default: 'USD' })
  @IsOptional()
  @IsString()
  currency?: string;
}

export class UpdateFeeRuleDto extends PartialType(CreateFeeRuleDto) {}
