import { IsString, IsNotEmpty, MaxLength } from 'class-validator';
import { ApiTags, ApiConsumes, ApiBody, ApiOperation, ApiResponse, ApiProperty } from '@nestjs/swagger';

export class AnalyzeTextDto {
  @IsString()
  @IsNotEmpty()
  @MaxLength(10000)
  text: string;
}

// Response DTOs for documentation
export class AiAnalysisResult {
  @ApiProperty({
    description: 'Probability that the text is AI-generated (0-1)',
    example: 0.85,
  })
  probability: number;

  @ApiProperty({
    description: 'Classification result',
    example: 'AI-generated',
    enum: ['AI-generated', 'Human-written', 'Uncertain'],
  })
  classification: string;

  @ApiProperty({
    description: 'Confidence level of the analysis',
    example: 'High',
    enum: ['Low', 'Medium', 'High'],
  })
  confidence: string;

  @ApiProperty({
    description: 'Additional details about the analysis',
    example: 'Text shows patterns consistent with AI generation',
  })
  details?: string;
}

export class SentenceAnalysisResult {
  @ApiProperty({
    description: 'The original sentence',
    example: 'This is a sample sentence.',
  })
  sentence: string;

  @ApiProperty({
    description: 'Probability that this sentence is AI-generated (0-1)',
    example: 0.72,
  })
  probability: number;

  @ApiProperty({
    description: 'Classification for this sentence',
    example: 'AI-generated',
    enum: ['AI-generated', 'Human-written', 'Uncertain'],
  })
  classification: string;
}

export class SentenceAnalysisResponse {
  @ApiProperty({
    description: 'Overall analysis result for the entire text',
    type: AiAnalysisResult,
  })
  overall: AiAnalysisResult;

  @ApiProperty({
    description: 'Analysis results for individual sentences',
    type: [SentenceAnalysisResult],
  })
  sentences: SentenceAnalysisResult[];
}

export class FileAnalysisResult extends AiAnalysisResult {
  @ApiProperty({
    description: 'Original filename of the uploaded file',
    example: 'document.pdf',
  })
  filename: string;

  @ApiProperty({
    description: 'File type that was analyzed',
    example: 'application/pdf',
  })
  fileType: string;

  @ApiProperty({
    description: 'Extracted text content from the file',
    example: 'This is the extracted text content...',
  })
  extractedText?: string;
}

export class AiNepaliAnalysisResult {
  @ApiProperty({
    description: 'Classification result: AI or Human',
    example: 'AI',
    enum: ['AI', 'Human'],
  })
  classification: string;

  @ApiProperty({
    description: 'Confidence percentage of the classification (0 to 100)',
    example: 99.4,
    type: Number,
  })
  confidence: number;

  @ApiProperty({
    description: 'Additional details about the analysis',
    example: 'Text shows patterns consistent with AI generation',
    required: false,
  })
  details?: string;
}

export class NepaliSentenceAnalysisResult {
  @ApiProperty({
    description: 'The analyzed Nepali sentence',
    example: 'नेपाल सुन्दर हिमाली देश हो जहाँ हिमाल, पहाड र तराईका भित्री भूभागहरू छन्।',
  })
  text: string;

  @ApiProperty({
    description: 'Classification result: AI or Human',
    example: 'Human',
    enum: ['AI', 'Human'],
  })
  result: string;

  @ApiProperty({
    description: 'Confidence score as a percentage (0–100)',
    example: 74.79,
  })
  likelihood: number;
}

export class NepaliSentenceAnalysisResponse {
  @ApiProperty({
    description: 'List of analyzed sentences with result and confidence',
    type: [NepaliSentenceAnalysisResult],
    isArray: true,
    example: [
      {
        text: 'नेपाल सुन्दर हिमाली देश हो जहाँ हिमाल, पहाड र तराईका भित्री भूभागहरू छन्।',
        result: 'Human',
        likelihood: 74.79,
      },
      {
        text: 'यहाँका मानिसहरू माया र सम्मानले भरिपूर्ण छन् र आफ्नो सांस्कृतिक र परम्परालाई ठूलो गर्वले जगेर्ना गर्छन्।',
        result: 'Human',
        likelihood: 64.64,
      },
      {
        text: 'नेपाली भाषा मधुरो र भावुक छ, जसले हाम्रो पहिचानलाई अझ बलियो बनाउँछ।',
        result: 'AI',
        likelihood: 54.09,
      },
      {
        text: 'नेपालको प्राकृतिक सौन्दर्यले सबैलाई मन्त्रमुग्ध बनाउँछ।',
        result: 'Human',
        likelihood: 85.12,
      },
      {
        text: 'हामी हाम्रो भाषा र संस्कृतिमा गर्व गर्छौं।',
        result: 'Human',
        likelihood: 78.33,
      },
    ],
  })
  analysis: NepaliSentenceAnalysisResult[];
}

export class NepaliFileAnalysisResult {
  @ApiProperty({
    description: 'label',
    example: 'AI',
    enum: ['AI', 'Human'],
  })
  label: string;
  @ApiProperty({
    description: 'Confidence',
    example: 0.85,
  })
  Confidence: number;
}

export class ImageAiDetector {
  @ApiProperty({
    description: 'Classification label',
    example: 'Human Generated',
    enum: ['AI ', 'Human'],
  })
  label: string;

  @ApiProperty({
    description: 'Confidence score for AI-generated likelihood (in %)',
    example: 2.99,
  })
  ai_confidence: number;

  @ApiProperty({
    description: 'Confidence score for Human-generated likelihood (in %)',
    example: 97.01,
  })
  human_confidence: number;
}

export class ElaDetect {
  @ApiProperty({
    description: 'Whether ELA (Error Level Analysis) detected suspicious artifacts in the image',
    example: true,
  })
  ela_score: boolean;

  @ApiProperty({
    description: 'Whether the image is likely edited based on ELA findings',
    example: true,
  })
  is_edited: boolean;
}

export class FFTDetect {
  @ApiProperty({
    description: 'Whether the image is likely edited based on FFT findings',
    example: true,
  })
  edited: boolean;
}
export class MetaDetect {
  @ApiProperty({
    description: '',
    example: 'ai_generated',
    enum: ['ai_generated', 'edited', 'undetermined'],
  })
  source: string;
}
export class ImageForensis {
  @ApiProperty({
    description: 'Final decision after combining FFT, ELA, and Metadata modules',
    example: 'authentic',
    enum: ['ai_generated', 'edited', 'possibly_edited', 'possibly_ai_generated', 'authentic', 'undetermined'],
  })
  decision: string;

  @ApiProperty({ type: FFTDetect })
  fft: FFTDetect;

  @ApiProperty({ type: ElaDetect })
  ela: ElaDetect;

  @ApiProperty({ type: MetaDetect })
  metadata: MetaDetect;
}
export class NepaliFileSentenceAnalysisResult {
  @ApiProperty({
    description: 'Classification label for the entire file',
    example: 'AI',
    enum: ['AI', 'Human'],
  })
  label: string;

  @ApiProperty({
    description: 'Confidence percentage for the classification (0-100)',
    example: 96.48,
  })
  confidence: number;

  @ApiProperty({
    description: 'List of analyzed sentences with result and confidence',
    type: [NepaliSentenceAnalysisResult],
    isArray: true,
  })
  analysis: NepaliSentenceAnalysisResult[];
}
