import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { is } from 'cheerio/dist/commonjs/api/traversing';
import { Type } from 'class-transformer';
import { IsNotEmpty, IsString, IsOptional, IsEnum, IsUrl, IsBoolean, IsDate, IsNumber, IsArray } from 'class-validator';
import { AttackType, AlertType } from 'common/enum/alert.enum';

export class CreateAlertDto {
  @ApiProperty({ description: 'Title of the alert', example: 'Cyber Attack on Government Server' })
  @IsNotEmpty()
  @IsString()
  title: string;

  @ApiProperty({ description: 'Detailed description of the attack', example: 'A sophisticated cyber attack targeted the main government server.' })
  @IsNotEmpty()
  @IsString()
  description: string;

  @ApiProperty({ description: 'Source of the information', example: 'Cyber Security Agency' })
  @IsNotEmpty()
  @IsString()
  source: string;

  @ApiPropertyOptional({ description: 'URL to the source of information', example: 'https://example.com/cyber-attack' })
  @IsOptional()
  @IsUrl()
  sourceUrl?: string;

  @ApiPropertyOptional({ description: 'Time of the attack', example: '2024-02-19T12:00:00Z' })
  @IsOptional()
  @IsDate()
  @Type(() => Date)
  attackTime?: Date;

  @ApiProperty({ description: 'Target country of the attack', example: 'Nepal' })
  @IsNotEmpty()
  @IsString()
  targetCountry: string;

  @ApiProperty({ description: 'Target organization of the attack', example: 'National Data Center' })
  @IsNotEmpty()
  @IsString()
  targetOrganization: string;

  @ApiPropertyOptional({ description: 'Information about the attacker', example: 'Anonymous Hackers' })
  @IsOptional()
  @IsString()
  attackerInfo?: string;

  @ApiProperty({ description: 'Type of attack', enum: AttackType, example: AttackType.DDOS })
  @IsEnum(AttackType)
  attackType: AttackType;

  @ApiProperty({ description: 'Type of alert', enum: AlertType, example: AlertType.AUTOMATIC })
  @IsEnum(AlertType)
  type: AlertType;

  @ApiPropertyOptional({ description: 'Severity level of the attack', example: 5 })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  score?: number;

  @ApiPropertyOptional({ description: 'Severity level of the attack', example: 5 })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  severity?: number;

  @ApiPropertyOptional({ description: 'Whether the attack is relevant to Nepal', example: true })
  @IsOptional()
  @IsBoolean()
  @Type(() => Boolean)
  isRelevantToNepal?: boolean;


  // imageurl
  @ApiPropertyOptional({ description: 'URL of the image related to the alert', example: 'https://example.com/image.jpg' })
  @IsOptional()
  @IsUrl()
  imageUrl?: string;

  @IsOptional()
  @IsArray()
  @Type(() => QuestionResponseDto)
  questionResponses?: QuestionResponseDto[];

  @ApiPropertyOptional({ description: 'Image file related to the alert' })
  @IsOptional()
  image?: Express.Multer.File;
}


export class QuestionResponseDto {
  @ApiProperty({ description: 'ID of the question', example: '1' })
  @IsString()
  questionId: string;

  @ApiProperty({ description: 'Text of the question', example: 'What is the nature of the threat?' })
  @IsString()
  questionText: string;

  @ApiProperty({ description: 'Answer to the question', example: 'Phishing campaign targeting government employees' })
  @IsString()
  answer: string;

  @ApiPropertyOptional({ description: 'Name of the poster', example: 'alert-poster-1.png' })
  @IsOptional()
  @IsString()
  posterName?: string;

  @ApiPropertyOptional({ type: 'string', format: 'binary', description: 'Attach a file (1 image, < 1MB)' })
  @IsOptional()
  attachment?: Express.Multer.File;

}
