"""POST /governance/elevate/ — JIT elevation"""
import uuid
from fastapi import APIRouter, Depends
from sqlmodel.ext.asyncio.session import AsyncSession
from gsap_broker.db import get_session
from gsap_broker.db_models import ElevationRequestDB
from gsap_broker.models import ElevateRequest, ElevateResponse

router = APIRouter()

@router.post("/elevate/", response_model=ElevateResponse, summary="Request JIT elevation")
async def elevate(request: ElevateRequest, db: AsyncSession = Depends(get_session)):
    er = ElevationRequestDB(id=uuid.uuid4(), role_name=request.role_name,
                            justification=request.justification, duration_minutes=request.duration_minutes)
    db.add(er); await db.commit()
    return ElevateResponse(status="pending", elevation_id=str(er.id),
                           message=f"Elevation to '{request.role_name}' requested.")
