import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsInt, IsOptional, Min } from 'class-validator';

/**
 * Query params for the program-scoped registration failures endpoint. Unlike the
 * per-job failures view, failures are addressed by `programId` (optionally
 * narrowed to one `sessionId`) and merged/de-staled across the program's job
 * chain, so the admin sees what is still failing without tracking job ids. The
 * list is paginated + enriched like the per-job view.
 */
export class ProgramFailuresQueryDto {
  @ApiProperty({ description: 'Program whose registration failures to list.', minimum: 1 })
  @Type(() => Number)
  @IsInt()
  @Min(1)
  programId: number;

  @ApiPropertyOptional({ description: 'Narrow to a single program session.', minimum: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  sessionId?: number;

  @ApiPropertyOptional({ description: 'Failures page (1-based). Default 1.', minimum: 1, default: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page = 1;

  @ApiPropertyOptional({ description: 'Failures per page. Default 20.', minimum: 1, default: 20 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  limit = 20;
}

/**
 * Query params for the program-scoped retry endpoint: re-run the current
 * failures of a `programId` (optionally one `sessionId`) as a fresh job.
 */
export class ProgramRetryQueryDto {
  @ApiProperty({ description: 'Program whose failures to retry.', minimum: 1 })
  @Type(() => Number)
  @IsInt()
  @Min(1)
  programId: number;

  @ApiPropertyOptional({ description: 'Narrow the retry to a single program session.', minimum: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  sessionId?: number;
}
