import { ApiPropertyOptional } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsBoolean, IsDateString, IsEnum, IsInt, IsNumber, IsOptional, IsString, Max, Min } from "class-validator";
import { AlertSeverity, CheckStatus, MonitoringCheckType } from "../enums/website-monitoring.enum";

export class BreachCheckResultQueryDto {
  @ApiPropertyOptional({
    description: 'Filter by website ID',
    example: 1,
  })
  @IsNumber()
  @IsOptional()
  @Type(() => Number)
  websiteId?: number;

  @ApiPropertyOptional({
    description: 'Filter by check type',
    enum: MonitoringCheckType,
    example: MonitoringCheckType.CONTENT_CHANGE,
  })
  @IsEnum(MonitoringCheckType)
  @IsOptional()
  checkType?: MonitoringCheckType;

  @ApiPropertyOptional({
    description: 'Filter by status',
    enum: CheckStatus,
    example: CheckStatus.FAIL,
  })
  @IsEnum(CheckStatus)
  @IsOptional()
  status?: CheckStatus;

  @ApiPropertyOptional({
    description: 'Filter by severity',
    enum:AlertSeverity,
    example: AlertSeverity.HIGH,
  })
  @IsEnum(AlertSeverity)
  @IsOptional()
  severity?: AlertSeverity;

  @ApiPropertyOptional({
    description: 'Filter results from this date',
    example: '2024-01-01T00:00:00.000Z',
  })
  @IsDateString()
  @IsOptional()
  fromDate?: Date;

  @ApiPropertyOptional({
    description: 'Filter results to this date',
    example: '2024-01-31T23:59:59.999Z',
  })
  @IsDateString()
  @IsOptional()
  toDate?: Date;

  @ApiPropertyOptional({
    description: 'Filter only results that generated alerts',
    example: true,
  })
  @IsBoolean()
  @IsOptional()
  @Type(() => Boolean)
  alertGenerated?: boolean;

  @ApiPropertyOptional({
    description: 'Page number for pagination',
    example: 1,
    minimum: 1,
    default: 1,
  })
  @IsInt()
  @Min(1)
  @IsOptional()
  @Type(() => Number)
  page?: number = 1;

  @ApiPropertyOptional({
    description: 'Number of items per page',
    example: 20,
    minimum: 1,
    maximum: 100,
    default: 20,
  })
  @IsInt()
  @Min(1)
  @Max(100)
  @IsOptional()
  @Type(() => Number)
  limit?: number = 20;

  @ApiPropertyOptional({
    description: 'Sort field',
    enum: ['timestamp', 'status', 'severity', 'responseTimeMs'],
    example: 'timestamp',
    default: 'timestamp',
  })
  @IsString()
  @IsOptional()
  sortBy?: 'timestamp' | 'status' | 'severity' | 'responseTimeMs' = 'timestamp';

  @ApiPropertyOptional({
    description: 'Sort order',
    enum: ['ASC', 'DESC'],
    example: 'DESC',
    default: 'DESC',
  })
  @IsEnum(['ASC', 'DESC'])
  @IsOptional()
  sortOrder?: 'ASC' | 'DESC' = 'DESC';
}
