import { ApiProperty, ApiPropertyOptional, OmitType } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import {
  IsDateString,
  IsIn,
  IsInt,
  IsNotEmpty,
  IsOptional,
  IsString,
  MaxLength,
  Min,
} from 'class-validator';

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

import { UpsertMyProgressReportIssueDto } from './upsert-my-progress-report-issue.dto';

// RGC Decision progress uses the same progress fields as an Issue update,
// but its status comes from PlenaryRgcDecision instead of IssueStatuses.
export class UpsertMyProgressReportRgcDecisionDto extends OmitType(
  UpsertMyProgressReportIssueDto,
  ['issueStatusId'] as const,
) {
  @ApiProperty({
    enum: RGC_DECISION_STATUS_VALUES,
    example: 'IN_PROGRESS',
  })
  @Transform(({ value }: { value: unknown }) =>
    normalizeRgcDecisionStatus(value),
  )
  @IsIn(RGC_DECISION_STATUS_VALUES)
  status!: string;

  @ApiPropertyOptional({ example: 3 })
  @Type(() => Number)
  @IsOptional()
  @IsInt()
  @Min(1)
  categoryId?: number;

  @ApiPropertyOptional({ example: 2 })
  @Type(() => Number)
  @IsOptional()
  @IsInt()
  @Min(1)
  indicatorId?: number;

  @ApiPropertyOptional({ example: 'Governance' })
  @IsOptional()
  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  category?: string;

  @ApiPropertyOptional({ example: '2026-07-20' })
  @IsOptional()
  @IsDateString()
  meetingDate?: string;

  @ApiProperty({ example: 'Dith Tina' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(255)
  focalPerson!: string;

  @ApiProperty({ example: 'Implement the agreed action.' })
  @IsString()
  @IsNotEmpty()
  decision!: string;

  @ApiPropertyOptional({ example: 'Inspection report' })
  @IsOptional()
  @IsString()
  verificationSource?: string;

  @ApiPropertyOptional({ example: 'https://example.com/report.pdf' })
  @IsOptional()
  @IsString()
  verificationLink?: string;
}
