import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsIn, IsNumber, IsOptional, IsUUID, Min } from 'class-validator';

const TRADE_DIRECTIONS = ['IMPORT', 'EXPORT', 'BOTH', 'DOMESTIC'] as const;

export class CreateWeightLimitRuleDto {
  @ApiProperty({ description: 'FK to container_types.id' })
  @IsUUID()
  containerTypeId!: string;

  @ApiProperty({
    enum: TRADE_DIRECTIONS,
    description: 'Trade direction: IMPORT, EXPORT, BOTH, or DOMESTIC',
  })
  @IsIn([...TRADE_DIRECTIONS])
  tradeDirection!: string;

  @ApiProperty({ description: 'Maximum allowed VGM in tons', minimum: 0 })
  @IsNumber()
  @Min(0)
  @Transform(({ value }) => Number(value))
  maxVgmTons!: number;

  @ApiPropertyOptional({
    description:
      'Hard per-unit weight ceiling in tons — above this the booking cannot be created. Null/omitted = no ceiling.',
    minimum: 0,
  })
  @IsOptional()
  @IsNumber()
  @Min(0)
  @Transform(({ value }) => (value === null || value === undefined || value === '' ? null : Number(value)))
  maxCapacityTons?: number | null;
}
