"""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 MemberRepository
from app.services.foundation import MemberService


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


def test_service_depends_on_repository_not_api():
    source = inspect.getsource(MemberService)
    assert "fastapi" not in source.lower()
    assert "MemberRepository" 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 NotificationProvider" in source
    assert "httpx" not in source
    assert "sqlalchemy" not in source
    assert "AsyncSession" not in source
