import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  ArrayNotEmpty,
  IsArray,
  IsDateString,
  IsNumber,
  IsString,
  IsUUID,
  Min,
  ValidateNested,
} from 'class-validator';

export class FundCallAllocationDto {
  @ApiProperty() @IsUUID() repartitionKeyId!: string;

  @ApiProperty({ example: 50000 })
  @IsNumber()
  @Min(0)
  amount!: number;
}

export class CreateFundCallDto {
  @ApiProperty() @IsUUID() complexId!: string;
  @ApiProperty() @IsUUID() fiscalYearId!: string;
  @ApiProperty({ example: 'Appel Q2 2026' }) @IsString() label!: string;
  @ApiProperty({ example: '2026-Q2' }) @IsString() period!: string;
  @ApiProperty({ example: '2026-05-15' }) @IsDateString() dueDate!: string;

  @ApiProperty({ type: [FundCallAllocationDto] })
  @IsArray()
  @ArrayNotEmpty()
  @ValidateNested({ each: true })
  @Type(() => FundCallAllocationDto)
  allocations!: FundCallAllocationDto[];
}
