"""
Pawprint Models - Platform Agnostic Definitions

Portable to: TypeScript, Pydantic, Django, SQLAlchemy, etc.

Hierarchy:
    pawprint (abstract)
    ├── artery    → Pulse  = Vein + Nest + Larder
    ├── album     → Book   = Template + Larder
    └── ward      → Table  = Tools + Nest + Larder

Shared components: Nest, Larder
System-specific: Vein (artery), Template (album), Tools (ward)

Rules:
    - Larder in album generated from Template = "Book (written)"
    - Same Larder exists independently in ward/artery
    - Nest contains runtime configs, credentials, targets
    - Larder contains data, provisions, stored content
"""

from dataclasses import dataclass, field
from typing import Optional, List
from enum import Enum


class Status(Enum):
    PENDING = "pending"
    PLANNED = "planned"
    BUILDING = "building"
    DEV = "dev"
    LIVE = "live"
    READY = "ready"


class System(Enum):
    ARTERY = "artery"
    ALBUM = "album"
    WARD = "ward"


# === Shared Components ===

@dataclass
class Nest:
    """Runtime environment configuration.

    Contains: credentials, targets, runtime configs.
    Shared across: artery, ward
    """
    name: str
    status: Status = Status.PENDING
    # References to actual config files/secrets
    config_path: Optional[str] = None


@dataclass
class Larder:
    """Data storage / provisions.

    Contains: data, transforms, parsers, dumps.
    Shared across: artery, album, ward

    Note: When generated from Template in album, appears as "Book (written)"
          but exists as independent Larder in ward/artery.
    """
    name: str
    status: Status = Status.PENDING
    # Optional source template (if generated)
    source_template: Optional[str] = None
    # Path to data
    data_path: Optional[str] = None


# === System-Specific Components ===

@dataclass
class Vein:
    """Connector (artery-specific).

    Single responsibility data connector.
    Examples: jira, google, slack, whatsapp, cash, vnc
    """
    name: str
    status: Status = Status.PENDING
    system: System = field(default=System.ARTERY, init=False)


@dataclass
class Template:
    """Documentation template (album-specific).

    Gherkin, BDD patterns, generators.
    Examples: feature-form, gherkin
    """
    name: str
    status: Status = Status.PENDING
    system: System = field(default=System.ALBUM, init=False)


@dataclass
class Tool:
    """Execution tool (ward-specific).

    Test runners, seeders, scripts.
    """
    name: str
    status: Status = Status.PENDING
    system: System = field(default=System.WARD, init=False)


# === Composed Types ===

@dataclass
class Pulse:
    """Composed data flow (artery).

    Pulse = Vein + Nest + Larder
    """
    name: str
    status: Status = Status.PENDING
    vein: Optional[Vein] = None
    nest: Optional[Nest] = None
    larder: Optional[Larder] = None
    system: System = field(default=System.ARTERY, init=False)


@dataclass
class Book:
    """Composed documentation (album).

    Book = Template + Larder

    Note: Output larder can be referenced independently in other systems.
    """
    name: str
    status: Status = Status.PENDING
    template: Optional[Template] = None
    larder: Optional[Larder] = None
    # If this book produces a larder, it's tracked here
    output_larder: Optional[Larder] = None
    system: System = field(default=System.ALBUM, init=False)


@dataclass
class Table:
    """Composed execution bundle (ward).

    Table = Tools + Nest + Larder
    """
    name: str
    status: Status = Status.PENDING
    tools: List[Tool] = field(default_factory=list)
    nest: Optional[Nest] = None
    larder: Optional[Larder] = None
    system: System = field(default=System.WARD, init=False)
