"""Domain models for ARS Title 25 statutes."""

from dataclasses import dataclass, field


@dataclass
class StatuteRecord:
    """A row from ars_25.csv — one statute's metadata."""
    chapter_number: int
    chapter_title: str
    article_number: int
    article_title: str
    section: str          # e.g. "25-403"
    title: str            # e.g. "Legal decision-making; best interests of child"
    url: str              # azleg.gov URL
    full_text: str = ""   # Scraped HTML → plain text


@dataclass
class StatuteChunk:
    """A chunk of statute text ready for embedding and storage."""
    section: str
    title: str
    chapter_number: int
    chapter_title: str
    article_number: int
    article_title: str
    url: str
    chunk_index: int
    chunk_text: str
    vector: list[float] = field(default_factory=list)


@dataclass
class SearchResult:
    """A single search result returned to the caller."""
    section: str
    title: str
    chunk_text: str
    score: float
    chapter_number: int
    chapter_title: str
    article_number: int
    article_title: str
    url: str

    def to_dict(self) -> dict:
        return {
            "section": self.section,
            "title": self.title,
            "text": self.chunk_text,
            "score": round(self.score, 4),
            "chapter": f"Ch. {self.chapter_number}: {self.chapter_title}",
            "article": f"Art. {self.article_number}: {self.article_title}",
            "url": self.url,
        }


@dataclass
class StatuteInfo:
    """Metadata-only view of a statute (no full text)."""
    section: str
    title: str
    chapter_number: int
    chapter_title: str
    article_number: int
    article_title: str

    def to_dict(self) -> dict:
        return {
            "section": self.section,
            "title": self.title,
            "chapter": f"Ch. {self.chapter_number}: {self.chapter_title}",
            "article": f"Art. {self.article_number}: {self.article_title}",
        }
