"""FastAPI dependency injection for authenticated user."""

from fastapi import HTTPException, Request

from ..models import AuthenticatedUser


async def get_current_user(request: Request) -> AuthenticatedUser:
    """FastAPI dependency that extracts the authenticated user.

    Usage:
        from conduit_auth.fastapi import get_current_user
        from conduit_auth import AuthenticatedUser

        @app.get("/api/projects")
        async def list_projects(user: AuthenticatedUser = Depends(get_current_user)):
            # user.tenant_id, user.email, etc.
            ...
    """
    user = getattr(request.state, "user", None)
    if user is None:
        raise HTTPException(status_code=401, detail="Not authenticated")
    return user
