import { Transform, Type } from 'class-transformer';
import {
  IsArray,
  IsIn,
  IsInt,
  IsNotEmpty,
  IsOptional,
  IsString,
  MaxLength,
  Min,
} from 'class-validator';

import {
  normalizeRgcDecisionStatus,
  RGC_DECISION_STATUS_VALUES,
} from './create-rgc-decision.dto';

export class UpdateRgcDecisionDto {
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  stakeholderId?: number;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  indicatorId?: number;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  categoryId?: number;

  @IsOptional()
  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  category?: string;

  @IsOptional()
  @IsString()
  @IsNotEmpty()
  meetingDate?: string;

  @IsOptional()
  @Transform(({ value }: { value: unknown }) =>
    normalizeRgcDecisionStatus(value),
  )
  @IsIn(RGC_DECISION_STATUS_VALUES)
  status?: string;

  @IsOptional()
  @IsString()
  @IsNotEmpty()
  @MaxLength(255)
  focalPerson?: string;

  @IsOptional()
  @IsString()
  @IsNotEmpty()
  decision?: string;

  @IsOptional()
  @IsString()
  verificationSource?: string;

  @IsOptional()
  @IsString()
  verificationLink?: string;

  // 🔥 Field សម្រាប់ទទួល Array នៃ Issue IDs ពេល Update
  @IsOptional()
  @IsArray()
  @Type(() => Number)
  @IsInt({ each: true })
  issueIds?: number[];
}
