"""Patient-scoped API dependencies — Phase 13.4."""
from __future__ import annotations

from uuid import UUID

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

from app.api.deps import get_db, require_tenant
from app.repositories.profiles import PatientRepository
from shared.exceptions import NotFoundError


async def require_patient_context(
    tenant_id: UUID = Depends(require_tenant),
    db: AsyncSession = Depends(get_db),
    x_patient_id: UUID = Header(..., alias="X-Patient-ID"),
) -> UUID:
    repo = PatientRepository(db)
    if await repo.get(tenant_id, x_patient_id) is None:
        raise NotFoundError("بیمار یافت نشد")
    return x_patient_id
