import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsIn,
  IsNumber,
  IsOptional,
  IsPositive,
  IsString,
  IsUUID,
  MinLength,
} from 'class-validator';

import { CUSTOMS_RISK_LEVELS } from '../entities/clearance-milestone.entity';
import { INCIDENT_TYPES } from '../entities/clearance-incident.entity';

export class AssignRiskDto {
  @ApiProperty({ enum: CUSTOMS_RISK_LEVELS })
  @IsIn(CUSTOMS_RISK_LEVELS as unknown as string[])
  riskLevel!: (typeof CUSTOMS_RISK_LEVELS)[number];

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  note?: string;
}

export class AdviseDutyDto {
  @ApiProperty({ description: 'Duty & tax amount advised to the customer' })
  @Type(() => Number)
  @IsNumber()
  @IsPositive()
  amount!: number;

  @ApiProperty({ example: 'ETB' })
  @IsString()
  @MinLength(1)
  currency!: string;

  @ApiPropertyOptional({ description: 'Customs declaration serial number' })
  @IsOptional()
  @IsString()
  declarationSerial?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  note?: string;
}

export class AssignStationDto {
  @ApiProperty({ description: 'Origin-station yard the shipment is routed to' })
  @IsUUID()
  stationYardId!: string;

  @ApiPropertyOptional({ description: 'GL staff user bound to this shipment' })
  @IsOptional()
  @IsUUID()
  staffId?: string;
}

export class ReportIncidentDto {
  @ApiProperty({ enum: INCIDENT_TYPES })
  @IsIn(INCIDENT_TYPES as unknown as string[])
  incidentType!: (typeof INCIDENT_TYPES)[number];

  @ApiProperty({ description: 'Mandatory free-text narrative of the anomaly' })
  @IsString()
  @MinLength(1)
  description!: string;
}

export class CompleteMilestoneDto {
  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  note?: string;
}
