"""Base repository class.

Every repository takes a SQLAlchemy Session in its constructor and uses
self.db for queries. Repositories are the ONLY layer that writes SQL;
services and routers never touch SQLAlchemy directly.

`ping()` lives here so the /api/health endpoint can verify DB connectivity
without inlining SELECT 1 into the router.
"""
from __future__ import annotations

from sqlalchemy import text
from sqlalchemy.orm import Session


class BaseRepository:
    def __init__(self, db: Session):
        self.db = db

    def ping(self) -> bool:
        """Smoke-test the database connection. Raises on failure."""
        self.db.execute(text("SELECT 1"))
        return True
