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

from app.adapters.db import get_session
from app.adapters.auth import get_current_user, UserContext

async def citizen_user(user: UserContext = Depends(get_current_user)) -> UserContext:
    if not user.has_scope("citizen:write"):
        raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
    return user

async def official_user(user: UserContext = Depends(get_current_user)) -> UserContext:
    if not (user.has_scope("official:read") or user.has_scope("official:write")):
        raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
    return user

DBSessionDep = Depends(get_session)
CitizenDep = Depends(citizen_user)
OfficialDep = Depends(official_user)
