from fastapi import APIRouter, Depends, HTTPException, status

from app.api.dependencies import OfficialDep
from app.domain.models import ExportRequest, ExportCreatedResponse, ExportStatusResponse
from app.service import exports_service

router = APIRouter(prefix="/exports", tags=["exports"])

@router.post(
    "",
    response_model=ExportCreatedResponse,
    status_code=status.HTTP_202_ACCEPTED,
)
async def create_export(
    payload: ExportRequest,
    official = OfficialDep,
):
    return await exports_service.start_export(payload)

@router.get(
    "/{job_id}",
    response_model=ExportStatusResponse,
)
async def get_export_status(
    job_id: str,
    official = OfficialDep,
):
    try:
        return await exports_service.get_export_status(job_id)
    except KeyError:
        raise HTTPException(status_code=404, detail="Export job not found")
