"""Agent governance — audit, compliance, and executive dashboards."""

from __future__ import annotations

from typing import Any, Dict, Optional

from .._resource import AsyncResource, Resource


class Governance(Resource):
    """Sync governance operations."""

    def summary(self) -> Dict[str, Any]:
        """Get governance summary dashboard."""
        return self._get("/v1/governance/summary")

    def audit(
        self,
        *,
        block: Optional[str] = None,
        operation: Optional[str] = None,
        limit: Optional[int] = None,
    ) -> Dict[str, Any]:
        """List audit trail entries."""
        query: Dict[str, str] = {}
        if block is not None:
            query["block"] = block
        if operation is not None:
            query["operation"] = operation
        if limit is not None:
            query["limit"] = str(limit)
        return self._get("/v1/governance/audit", query or None)

    def audit_stats(self) -> Dict[str, Any]:
        """Get audit trail statistics."""
        return self._get("/v1/governance/audit/stats")

    def compliance(self) -> Dict[str, Any]:
        """Run compliance scan on memory entries."""
        return self._post("/v1/governance/compliance/scan")

    def sleep_time_report(self) -> Dict[str, Any]:
        """Get sleep-time compute report."""
        return self._get("/v1/governance/sleep-time/report")


class AsyncGovernance(AsyncResource):
    """Async governance operations."""

    async def summary(self) -> Dict[str, Any]:
        return await self._get("/v1/governance/summary")

    async def audit(
        self,
        *,
        block: Optional[str] = None,
        operation: Optional[str] = None,
        limit: Optional[int] = None,
    ) -> Dict[str, Any]:
        query: Dict[str, str] = {}
        if block is not None:
            query["block"] = block
        if operation is not None:
            query["operation"] = operation
        if limit is not None:
            query["limit"] = str(limit)
        return await self._get("/v1/governance/audit", query or None)

    async def audit_stats(self) -> Dict[str, Any]:
        return await self._get("/v1/governance/audit/stats")

    async def compliance(self) -> Dict[str, Any]:
        return await self._post("/v1/governance/compliance/scan")

    async def sleep_time_report(self) -> Dict[str, Any]:
        return await self._get("/v1/governance/sleep-time/report")
