"""Abstract base for all health check implementations."""
from abc import ABC, abstractmethod


class HealthCheck(ABC):
    """
    Interface that all health checks must implement.

    Built-in implementations live in ``fk_utils.health.checks``.
    Microservices can define their own checks by subclassing this class
    and passing instances to the framework health check class.

    Example — custom check in a microservice::

        from fk_utils.health.base import HealthCheck

        class InterestCalculationCheck(HealthCheck):
            def __init__(self, session):
                self._session = session

            @property
            def name(self) -> str:
                return "interest_calculation"

            def check(self) -> str:
                try:
                    self._session.execute(text("SELECT 1 FROM loans LIMIT 1"))
                    return "healthy"
                except Exception as e:
                    return f"unhealthy: {e}"
    """

    @property
    @abstractmethod
    def name(self) -> str:
        """Key that will appear in the ``databases`` section of the response."""

    @abstractmethod
    def check(self) -> str:
        """
        Executes the health check.

        :return: ``"healthy"`` on success, ``"unhealthy: <reason>"`` on failure.
        """
