import {
  IsEnum,
  IsInt,
  IsOptional,
  IsString,
  IsArray,
  IsUrl,
  IsDate,
  IsNotEmpty,
  MaxLength,
  Min,
  Max,
  IsNumber,
  ValidateNested,
  IsBoolean,
  isBoolean,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { MonitoringCheckType, OperationalStatus, WebsiteCategory } from '../enums/website-monitoring.enum';

enum MonitoringStage {
  SCANNED = 'Scanned',
  REVIEW = 'Review',
  ARCHIVED = 'Archived',
  DELETED = 'Deleted',
}

export class CreateBreachCheckWebsiteDto {
  @ApiProperty({
    description: 'Website name',
    example: 'My E-commerce Site',
    maxLength: 255,
  })
  @IsString()
  name: string;

  @ApiProperty({
    description: 'Website URL',
    example: 'https://example.com',
  })
  @IsUrl()
  url: string;

  @ApiProperty({
    description: 'Website category',
    enum: WebsiteCategory,
    default: WebsiteCategory.OTHER,
  })
  @IsEnum(WebsiteCategory)
  @IsOptional()
  category?: WebsiteCategory = WebsiteCategory.OTHER;

  @ApiProperty({
    description: 'Monitoring frequency in minutes',
    example: 60,
    minimum: 5,
    maximum: 1440,
  })
  @IsInt()
  @Min(5)
  @Max(1440)
  @IsOptional()
  monitoringFrequencyMinutes?: number = 60;

  @ApiProperty({
    description: 'Website stage',
    enum: MonitoringStage,
    example: 'Scanned',
  })
  @IsEnum(MonitoringStage)
  @IsOptional()
  stage?: MonitoringStage = MonitoringStage.SCANNED;

  @ApiPropertyOptional({
    description: 'Whether this is a false positive',
    default: false,
  })
  @IsBoolean()
  @IsOptional()
  isFalsePositive?: boolean = false;

  @ApiProperty({
    description: 'Operational status',
    enum: OperationalStatus,
    default: OperationalStatus.UNKNOWN,
  })
  @IsEnum(OperationalStatus)
  @IsOptional()
  operationalStatus?: OperationalStatus = OperationalStatus.UNKNOWN;

  @ApiProperty({
    description: 'Enabled monitoring checks',
    type: [String],
    enum: MonitoringCheckType,
    example: [MonitoringCheckType.DEFACEMENT],
  })
  @IsArray()
  @IsEnum(MonitoringCheckType, { each: true })
  enabledChecks: MonitoringCheckType[];

  @ApiPropertyOptional({
    description: 'Whether to receive alerts',
    default: true,
  })
  @IsBoolean()
  @IsOptional()
  receiveAlerts?: boolean = true;

  @ApiProperty({
    description: 'Alert threshold score',
    example: 50,
    minimum: 0,
    maximum: 100,
    default: 50,
  })
  @IsInt()
  @Min(0)
  @Max(100)
  @IsOptional()
  alertThreshold?: number = 50;

  @ApiPropertyOptional({
    description: 'Additional notes',
    example: 'Critical production website',
  })
  @IsString()
  @IsOptional()
  notes?: string;

  @ApiProperty({
    description: 'Tags for categorization',
    type: [String],
    example: ['production', 'critical', 'ecommerce'],
  })
  @IsArray()
  @IsString({ each: true })
  @IsOptional()
  tags?: string[] = [];

  @ApiProperty({
    description: 'Organization ID',
    example: 1,
  })
  @IsNumber()
  organizationId: number;

  @ApiPropertyOptional({
    description: 'Whether to check content with AI',
    default: false,
  })
  @IsBoolean()
  @IsOptional()
  checkContentWithAI?: boolean = true;
}
