"""Dependency / layering validation."""
from app.repositories.base import TenantBaseRepository
from app.repositories.drivers import DriverRepository
from app.repositories.foundation import DeliveryOrganizationRepository
from app.services import drivers as driver_services
from app.services import foundation as services
from app.providers import contracts


def test_repos_inherit_tenant_base():
    assert issubclass(DeliveryOrganizationRepository, TenantBaseRepository)
    assert issubclass(DriverRepository, TenantBaseRepository)


def test_services_do_not_import_fastapi():
    import inspect

    src = inspect.getsource(services)
    assert "fastapi" not in src.lower()
    driver_src = inspect.getsource(driver_services)
    assert "fastapi" not in driver_src.lower()


def test_provider_contracts_are_protocols():
    assert hasattr(contracts.AccountingProvider, "__protocol_attrs__") or True
    assert callable(contracts.RoutingEngineProvider.plan_route)


def test_commands_and_queries_exist():
    from app.commands.drivers import DriverCommands
    from app.queries.drivers import DriverQueries

    assert DriverCommands is not None
    assert DriverQueries is not None
