import { RunnerJobStatus } from "@prisma/client";
import { IsUUID, IsEnum, IsOptional, IsInt, Min, Max, IsString } from "class-validator";
import { Type, Transform } from "class-transformer";

/**
 * DTO for querying runner jobs with filters and pagination
 */
export class QueryJobsDto {
  @IsOptional()
  @IsUUID("4", { message: "workspaceId must be a valid UUID" })
  workspaceId?: string;

  @IsOptional()
  @IsEnum(RunnerJobStatus, { each: true, message: "status must be a valid RunnerJobStatus" })
  @Transform(({ value }) =>
    value === undefined ? undefined : Array.isArray(value) ? value : [value]
  )
  status?: RunnerJobStatus | RunnerJobStatus[];

  @IsOptional()
  @IsString({ message: "type must be a string" })
  type?: string;

  @IsOptional()
  @IsUUID("4", { message: "agentTaskId must be a valid UUID" })
  agentTaskId?: string;

  @IsOptional()
  @Type(() => Number)
  @IsInt({ message: "page must be an integer" })
  @Min(1, { message: "page must be at least 1" })
  page?: number;

  @IsOptional()
  @Type(() => Number)
  @IsInt({ message: "limit must be an integer" })
  @Min(1, { message: "limit must be at least 1" })
  @Max(100, { message: "limit must not exceed 100" })
  limit?: number;
}
