"""Dependency / layering validation."""
from pathlib import Path

from app.repositories.base import TenantBaseRepository
from app.repositories import analytics as analytics_repos
from app.repositories import catalog as catalog_repos
from app.repositories import connectors as connectors_repos
from app.repositories import foundation as repos
from app.repositories import kitchen as kitchen_repos
from app.repositories import pos_lite as pos_lite_repos
from app.repositories import pos_pro as pos_pro_repos
from app.repositories import qr as qr_repos
from app.repositories import table_service as table_service_repos


def test_repositories_inherit_tenant_base():
    for module in (
        repos,
        catalog_repos,
        qr_repos,
        table_service_repos,
        pos_lite_repos,
        pos_pro_repos,
        kitchen_repos,
        connectors_repos,
        analytics_repos,
    ):
        for name in dir(module):
            obj = getattr(module, name)
            if isinstance(obj, type) and name.endswith("Repository"):
                assert issubclass(obj, TenantBaseRepository), name


def test_services_have_no_fastapi_import():
    root = Path(__file__).resolve().parents[1] / "services"
    for path in root.glob("*.py"):
        text = path.read_text(encoding="utf-8")
        assert "fastapi" not in text.lower()


def test_provider_contracts_are_protocol_only():
    text = (
        Path(__file__).resolve().parents[1] / "providers" / "contracts.py"
    ).read_text(encoding="utf-8")
    assert "Protocol" in text
    assert "httpx" not in text
    assert "sqlalchemy" not in text
