import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsDateString, 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;

  @ApiProperty({ description: 'Date from which this rule is active (ISO date)', example: '2024-01-01' })
  @IsDateString()
  effectiveFrom!: string;

  @ApiPropertyOptional({ description: 'Date when this rule expires (ISO date). Null = currently active', example: '2025-12-31' })
  @IsOptional()
  @IsDateString()
  effectiveTo?: string;
}
