"""Runtime monitor — health, audit trail, and quality status.

Reuses:
    - ``src.evaluation.health_dashboard.get_dashboard()``
    - ``src.governance.audit_trail.query_audit_trail()``
"""

from __future__ import annotations

from typing import Any, Dict, List, Optional

from databridge_core.sdk.core.context import SDKContext
from databridge_core.sdk.core.exceptions import NotImplementedStubError


class RuntimeMonitor:
    """Monitor deployed DataBridge solutions at runtime.

    Provides health checks, audit trail queries, and quality
    status for enterprise clients managing deployed solutions.

    Reuses:
        - ``src.evaluation.health_dashboard.get_dashboard()``
        - ``src.evaluation.health_dashboard.collect_health_snapshot()``
        - ``src.governance.audit_trail.query_audit_trail()``
        - ``src.governance.audit_trail.get_decision_provenance()``

    Usage::

        monitor = RuntimeMonitor(ctx=ctx)
        health = monitor.health_check()
        audit = monitor.query_audit(start_date="2026-01-01")
        quality = monitor.quality_status()
    """

    def __init__(self, ctx: SDKContext):
        self._ctx = ctx

    def health_check(
        self,
        include_trends: bool = True,
        include_regressions: bool = True,
    ) -> Dict[str, Any]:
        """Get comprehensive health dashboard.

        Reuse: ``src.evaluation.health_dashboard.get_dashboard(
            include_trends, include_regressions
        )``
        """
        raise NotImplementedStubError(
            "RuntimeMonitor",
            "health_check",
            "src.evaluation.health_dashboard.get_dashboard("
            "include_trends, include_regressions)",
        )

    def query_audit(
        self,
        start_date: Optional[str] = None,
        end_date: Optional[str] = None,
        decision_types: Optional[List[str]] = None,
        actor: Optional[str] = None,
        module: Optional[str] = None,
        limit: int = 50,
    ) -> Dict[str, Any]:
        """Query the governance audit trail.

        Reuse: ``src.governance.audit_trail.query_audit_trail(
            AuditQuery(start_date, end_date, decision_types, actor, module, limit)
        )``
        """
        raise NotImplementedStubError(
            "RuntimeMonitor",
            "query_audit",
            "src.governance.audit_trail.query_audit_trail(AuditQuery(...))",
        )

    def decision_provenance(self, decision_id: str) -> Dict[str, Any]:
        """Trace provenance of a specific decision.

        Reuse: ``src.governance.audit_trail.get_decision_provenance(decision_id)``
        """
        raise NotImplementedStubError(
            "RuntimeMonitor",
            "decision_provenance",
            "src.governance.audit_trail.get_decision_provenance(decision_id)",
        )

    def quality_status(self) -> Dict[str, Any]:
        """Get current quality status across all modules.

        Reuse: ``src.evaluation.health_dashboard.collect_health_snapshot()``
        """
        raise NotImplementedStubError(
            "RuntimeMonitor",
            "quality_status",
            "src.evaluation.health_dashboard.collect_health_snapshot().to_dict()",
        )
