from __future__ import annotations

from dataclasses import asdict, dataclass, field
from typing import Any, Literal

Route = Literal["digital_text", "local_ocr"]
Status = Literal["ok", "failed"]


@dataclass
class PageAnalysis:
    page: int
    text_chars: int
    alpha_chars: int
    accent_ratio: float
    mojibake_hits: int
    image_count: int


@dataclass
class PdfAnalysis:
    input_path: str
    page_count: int
    file_size_mb: float
    pages: list[PageAnalysis]
    has_text_layer: bool
    scan_likelihood: str
    recommended_route: Route
    warnings: list[str] = field(default_factory=list)


@dataclass
class DependencyStatus:
    tesseract_available: bool
    tesseract_path: str | None
    vie_available: bool
    tessdata_prefix: str | None = None
    warnings: list[str] = field(default_factory=list)


@dataclass
class ConversionResult:
    status: Status
    job_id: str
    route: Route
    markdown_path: str | None
    quality_report_path: str
    log_path: str
    warnings: list[str]
    quality: dict[str, Any]
    error: str | None = None
    markdown: str | None = None
    markdown_filename: str | None = None

    def to_dict(self) -> dict[str, Any]:
        return asdict(self)
