"""Dependency direction and DI tests."""
from __future__ import annotations

import inspect

from app.api import deps
from app.repositories.base import TenantBaseRepository
from app.repositories.foundation import LeadRepository
from app.services.foundation import LeadService


def test_repository_pattern():
    assert issubclass(LeadRepository, TenantBaseRepository)
    assert LeadRepository.model is not None


def test_service_depends_on_repository_not_api():
    source = inspect.getsource(LeadService)
    assert "fastapi" not in source.lower()
    assert "LeadRepository" in source


def test_api_deps_expose_tenant_and_db():
    assert hasattr(deps, "require_tenant")
    assert hasattr(deps, "get_db")
    assert hasattr(deps, "get_current_user")


def test_providers_are_protocols_only():
    import app.providers.contracts as contracts

    source = inspect.getsource(contracts)
    assert "async def" in source
    assert "class AutomationProvider" in source
    # No concrete HTTP/DB implementation in contracts module
    assert "httpx" not in source
    assert "sqlalchemy" not in source
    assert "AsyncSession" not in source
