"""Execution DTOs — pure data models for pathway execution.

These are the data types that describe execution state and events.
They live in models/ (not nodes/) because they have no node dependencies,
which avoids the circular import: llm/invoke -> nodes/execution -> nodes/core -> llm/invoke.

PathwayRecord remains in nodes/execution.py because it references Context.
"""

from datetime import datetime
from enum import Enum

from pydantic import BaseModel, Field

from core.common import JsonObject


class PathwayStatus(Enum):
    """Status of a pathway execution."""

    PENDING = "pending"
    RUNNING = "running"
    COMPLETED = "completed"
    FAILED = "failed"
    CANCELLED = "cancelled"
    PAUSED = "paused"
    AWAITING_APPROVAL = "awaiting_approval"


class PathwayEvent(BaseModel):
    """An event that occurred during execution."""

    model_config = {"extra": "allow"}

    timestamp: datetime = Field(default_factory=datetime.utcnow)
    event_type: str
    node_id: str | None = None
    pathway_id: str | None = None
    data: JsonObject = Field(default_factory=dict)
    error: str | None = None


class PathwayMetrics(BaseModel):
    """Metrics collected during execution."""

    model_config = {"extra": "allow"}

    start_time: datetime | None = None
    end_time: datetime | None = None
    duration_ms: float | None = None
    nodes_executed: int = 0
    nodes_succeeded: int = 0
    nodes_failed: int = 0
    nodes_skipped: int = 0


__all__ = [
    "PathwayEvent",
    "PathwayMetrics",
    "PathwayStatus",
]
