"""API dependencies — auth, database session."""

from fastapi import Depends, Header, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession

from app.database import get_db


async def get_user_id(
    x_gateway_user_id: str = Header(None, alias="X-Gateway-User-Id"),
) -> str:
    """Extract authenticated user ID from gateway-injected header."""
    if not x_gateway_user_id:
        raise HTTPException(status_code=401, detail="Not authenticated")
    return x_gateway_user_id


async def get_db_session() -> AsyncSession:
    """Provide an async database session."""
    async for session in get_db():
        yield session
