"""Analysis-related domain models.

Module represents a logical code unit discovered during static analysis.
FileSnapshot tracks file state for change detection.
"""

from __future__ import annotations

from datetime import (
    datetime,  # noqa: TCH003 — Pydantic resolves datetime at runtime for field schema
)

from pydantic import BaseModel, Field

from unfamiliar.constants import (  # noqa: TCH001 — Pydantic resolves enum at runtime for field schema
    InvestigationCategory,
)


class Module(BaseModel):
    """A logical code unit identified during static analysis.

    Modules group related files and functionality. They are used
    to organize missions and understand codebase structure.

    Attributes:
        id: Database primary key. None until persisted.
        campaign_id: Foreign key to the parent campaign.
        name: Human-readable module name.
        path: Primary path/directory for the module.
        description: Brief description of the module's purpose.
        file_count: Number of files belonging to this module.
        category_relevance: Which investigation categories are relevant.
        security_relevant: Whether this module handles security concerns.
        created_at: Timestamp when module was created.
        updated_at: Timestamp when module was last modified.
    """

    id: int | None = None
    campaign_id: int
    name: str
    path: str
    description: str
    file_count: int = 0
    category_relevance: list[InvestigationCategory] = Field(default_factory=list)
    security_relevant: bool = False
    created_at: datetime | None = None
    updated_at: datetime | None = None


class FileSnapshot(BaseModel):
    """Tracks file state at analysis time for change detection.

    Used in v1.1 to detect when files have changed and need
    re-analysis. Stored per-campaign to track evolution over time.

    Attributes:
        id: Database primary key. None until persisted.
        campaign_id: Foreign key to the parent campaign.
        file_path: Path to the file, relative to repo root.
        file_hash: SHA-256 hash of file contents at analysis time.
        last_analyzed: When the file was last analyzed.
    """

    id: int | None = None
    campaign_id: int
    file_path: str
    file_hash: str
    last_analyzed: datetime | None = None
