"""Configuração central do OCR."""

from dataclasses import dataclass, field
from multiprocessing import cpu_count
from pathlib import Path


@dataclass
class OcrConfig:
    """Parâmetros de configuração do OCR."""

    model: str = "mobile"
    device: str = "auto"
    scale: int = 2
    workers: int = field(default_factory=lambda: min(cpu_count(), 8))
    mode: str = "text"
    min_score: float = 0.5
    output_dir: Path = field(default_factory=lambda: Path("output"))
    verbose: bool = False

    def __post_init__(self):
        self.output_dir = Path(self.output_dir)
        if self.model not in ("mobile", "server"):
            raise ValueError(f"model deve ser 'mobile' ou 'server', got '{self.model}'")
        if self.mode not in ("text", "structure"):
            raise ValueError(f"mode deve ser 'text' ou 'structure', got '{self.mode}'")
        if self.scale not in (1, 2, 3):
            raise ValueError(f"scale deve ser 1, 2 ou 3, got {self.scale}")
