"""DAG checkpoint model for workflow resume.

A ``DAGCheckpoint`` captures the state of a DAG execution after each
node completes, enabling resume-from-failure for agentic workflows.
"""

from __future__ import annotations

import time

from pydantic import BaseModel, Field

from core.common import JsonObject


class DAGCheckpoint(BaseModel):
    """Snapshot of a DAG execution for resume-from-failure.

    Attributes
    ----------
    execution_id
        Unique execution identifier.
    pathway_id
        Pathway that was executing.
    completed_nodes
        Map of node_id -> serialised outputs for already-completed nodes.
    failed_node
        Node that failed (if the checkpoint was triggered by failure).
    pending_approval_node
        Node that requires human approval before continuing.
    inputs
        Original pathway inputs.
    timestamp
        When the checkpoint was created (epoch seconds).
    """

    execution_id: str
    pathway_id: str
    completed_nodes: dict[str, JsonObject] = Field(default_factory=dict)
    failed_node: str | None = None
    pending_approval_node: str | None = None
    inputs: JsonObject = Field(default_factory=dict)
    timestamp: float = Field(default_factory=time.time)


__all__ = ["DAGCheckpoint"]
