"""Campaign and Briefing domain models.

Campaign represents a single investigation of a codebase.
Briefing holds the LLM-generated structured analysis results.
"""

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
    CampaignMode,
    CampaignStatus,
    CharacterArchetype,
    Theme,
)


class Campaign(BaseModel):
    """A single investigation of a codebase.

    Campaigns track the overall progress of understanding a repository
    through gamified missions. One campaign per repository path.

    Attributes:
        id: Database primary key. None until persisted.
        repo_path: Absolute path to the repository being investigated.
        schema_version: Data model version for upgrade detection.
        mode: Campaign mode (onboarding vs assessment). v1.1 field with default.
        character: Character archetype affecting mission ordering. v1.1 field.
        status: Current lifecycle state. Progresses forward only.
        theme: Visual theme for the TUI.
        created_at: Timestamp when campaign was created.
        updated_at: Timestamp when campaign was last modified.
    """

    id: int | None = None
    repo_path: str
    schema_version: str = "1.0"
    mode: CampaignMode = Field(default=CampaignMode.ONBOARDING)
    character: CharacterArchetype = Field(default=CharacterArchetype.DETECTIVE)
    status: CampaignStatus = Field(default=CampaignStatus.INITIALIZING)
    theme: Theme = Field(default=Theme.FILM_NOIR)
    created_at: datetime | None = None
    updated_at: datetime | None = None


class Briefing(BaseModel):
    """Structured analysis results for a campaign.

    Generated by the LLM after initial codebase analysis. Provides
    a high-level overview of the codebase's architecture, technology
    stack, and security posture.

    One-to-one relationship with Campaign.

    Attributes:
        id: Database primary key. None until persisted.
        campaign_id: Foreign key to the parent campaign.
        summary: Natural language summary of the codebase.
        tech_stack: List of detected technologies, frameworks, and libraries.
        security_posture: Assessment of security-relevant patterns found.
        created_at: Timestamp when briefing was generated.
        updated_at: Timestamp when briefing was last updated.
    """

    id: int | None = None
    campaign_id: int
    summary: str
    tech_stack: list[str] = Field(default_factory=list)
    security_posture: str
    created_at: datetime | None = None
    updated_at: datetime | None = None
