import { ApiPropertyOptional } from '@nestjs/swagger';
import { UpdateWorkingGroupIssueDto } from '@/modules/working-group-issues/dto/update-working-group-issue.dto';
import { Type } from 'class-transformer';
import {
  ArrayMaxSize,
  ArrayNotEmpty,
  ArrayUnique,
  IsArray,
  IsBoolean,
  IsInt,
  IsOptional,
  Min,
} from 'class-validator';

/**
 * One body for both ways of editing an issue:
 * - the edit form sends the full issue (multipart, with an attachment);
 * - the table sends just the field it changed.
 *
 * Every field is optional, and the service acts on whichever ones arrive.
 */
export class UpdateIssueDto extends UpdateWorkingGroupIssueDto {
  @ApiPropertyOptional({
    type: [Number],
    example: [3],
    description:
      'One ministry stakeholder id. It becomes the primary agency ' +
      '(agencyOrder 1). Sending an empty list is rejected.',
  })
  @IsOptional()
  @IsArray()
  @ArrayNotEmpty()
  @ArrayMaxSize(1)
  @ArrayUnique()
  @Type(() => Number)
  @IsInt({ each: true })
  @Min(1, { each: true })
  governmentAgencyIds?: number[];

  @ApiPropertyOptional({
    example: 4,
    description: 'The new issue status id.',
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  issueStatusId?: number;

  @ApiPropertyOptional({
    example: true,
    description:
      'True flags the issue for the plenary, false takes the flag off.',
  })
  @IsOptional()
  @IsBoolean()
  escalation?: boolean;
}
