"""Protocol interfaces for runtime storage hooks."""

from __future__ import annotations

from collections.abc import Mapping
from typing import Any, Protocol

from oneiric.runtime.activity import DomainActivity


class ActivityStoreProtocol(Protocol):
    def get(self, domain: str, key: str) -> DomainActivity: ...
    def all_for_domain(self, domain: str) -> dict[str, DomainActivity]: ...
    def set(self, domain: str, key: str, state: DomainActivity) -> None: ...
    def snapshot(self) -> dict[str, dict[str, DomainActivity]]: ...


class WorkflowCheckpointStoreProtocol(Protocol):
    def load(self, workflow_key: str) -> dict[str, Any]: ...
    def save(self, workflow_key: str, checkpoint: Mapping[str, Any]) -> None: ...
    def clear(self, workflow_key: str) -> None: ...


class WorkflowExecutionStoreProtocol(Protocol):
    def start_run(self, workflow_key: str, run_id: str, started_at: str) -> None: ...
    def finish_run(
        self, run_id: str, status: str, ended_at: str, error: str | None = None
    ) -> None: ...
    def start_node(self, run_id: str, node_key: str, started_at: str) -> None: ...
    def finish_node(
        self,
        run_id: str,
        node_key: str,
        status: str,
        ended_at: str,
        attempts: int | None = None,
        error: str | None = None,
    ) -> None: ...
    def load_run(self, run_id: str) -> dict[str, Any] | None: ...
    def load_nodes(self, run_id: str) -> list[dict[str, Any]]: ...
