"""Example plugin that adds a ``/plugin/health`` endpoint to a FastAPI app."""

from __future__ import annotations

from datetime import datetime, timezone
from typing import Any

try:
    from fastapi import FastAPI
except ImportError:  # pragma: no cover
    FastAPI = Any  # type: ignore[misc,assignment]

from plugin import Plugin


class HealthCheckPlugin(Plugin):
    """Adds a simple health endpoint to the host FastAPI application."""

    name = "health_check"
    version = "1.0.0"
    description = "Exposes /plugin/health for plugin-aware health checks."
    dependencies: list[str] = []

    def __init__(self) -> None:
        super().__init__()
        self.started_at = datetime.now(timezone.utc).isoformat()

    def register(self, app: FastAPI) -> None:
        @app.get("/plugin/health")
        async def plugin_health() -> dict[str, Any]:
            return {
                "status": "ok",
                "plugin": self.name,
                "version": self.version,
                "started_at": self.started_at,
            }

    def health(self) -> dict[str, Any]:
        data = super().health()
        data["started_at"] = self.started_at
        return data
