from __future__ import annotations

from collections.abc import Callable, Mapping
from dataclasses import dataclass, field
from typing import Literal


OperationalCheckState = Literal["ok", "warning", "error", "inactive"]


@dataclass(frozen=True, slots=True)
class OperationalCheck:
    """A bounded module-owned runtime check exposed through the Ops module."""

    id: str
    label: str
    state: OperationalCheckState
    detail: str
    readiness_critical: bool = False
    metrics: Mapping[str, object] = field(default_factory=dict)

    def as_dict(self) -> dict[str, object]:
        return {
            "id": self.id,
            "label": self.label,
            "state": self.state,
            "detail": self.detail,
            "readiness_critical": self.readiness_critical,
            "metrics": dict(self.metrics),
        }


OperationalCheckProvider = Callable[[], OperationalCheck]


@dataclass(frozen=True, slots=True)
class OperationalCheckProviderRegistration:
    """Register one independently executable operational check."""

    module_id: str
    check_id: str
    provider: OperationalCheckProvider
    cache_seconds: int = 60

