/**
 * Content Analysis Engine — TypeScript port of Rank Math's analyzer.
 * Original: assets/admin/src/analyzer/{Analysis,Paper,Researcher}.js
 */

export type ScoreType = "ok" | "fail" | "fair" | "good" | "best" | "empty";

export interface AnalysisResult {
  /** Unique identifier for the check (e.g. "keywordInTitle") */
  id: string;
  /** Human title shown in the UI */
  title: string;
  /** Score awarded (0..maxScore). Higher = better. */
  score: number;
  /** Maximum score this check can award. */
  maxScore: number;
  /** Type of result for UI styling. */
  type: ScoreType;
  /** Localized message explaining the result. */
  text: string;
  /** Optional tooltip with extra context. */
  tooltip?: string;
  /** Severity for sorting fails first (10=critical, 1=info). */
  severity: number;
}

export interface Paper {
  /** Article title (also used as SEO title fallback). */
  title: string;
  /** Article SEO title (metaTitle). Defaults to `title` when empty. */
  metaTitle: string;
  /** Article slug. */
  slug: string;
  /** SEO meta description. */
  metaDesc: string;
  /** Focus keyword (primary phrase to optimize for). */
  keyword: string;
  /** Comma-separated additional keywords. */
  keywords: string[];
  /** Plain-text body (markdown source is OK). */
  text: string;
  /** Cover image URL (or null). */
  coverImage: string | null;
  /** Cover alt text (auto-derived from title when empty). */
  coverAlt: string | null;
  /** Article subheadings extracted from markdown (## …). */
  subheadings: string[];
  /** Internal-link URLs found in body (relative or same-host). */
  internalLinks: string[];
  /** External-link URLs found in body. */
  externalLinks: string[];
  /** Image URLs found in body. */
  images: Array<{ src: string; alt: string }>;
  /** Site host (e.g. v2.finzone.io.vn) used to classify links. */
  host: string;
  /** Locale ("en" or "vi") — affects readability + word count. */
  locale: "en" | "vi";
}

export type AnalysisCheck = (paper: Paper) => AnalysisResult | null;

export interface AnalysisReport {
  /** Aggregate 0..100 score. */
  score: number;
  /** Letter grade for quick UI ("A"…"F"). */
  grade: "A" | "B" | "C" | "D" | "F";
  /** Per-check results (sorted: fails first, then info). */
  checks: AnalysisResult[];
  /** Quick stats for the editor sidebar. */
  stats: {
    wordCount: number;
    readMinutes: number;
    fleschScore: number | null;
    keywordDensity: number;
    internalLinks: number;
    externalLinks: number;
    images: number;
    subheadings: number;
  };
}
