from app.domain.models import ExportRequest, ExportCreatedResponse, ExportStatusResponse
from app.domain.models import ExportJobStatus
from app.adapters import jobs

async def start_export(req: ExportRequest) -> ExportCreatedResponse:
    job_id = jobs.create_export_job(
        case_id=req.caseId,
        target_system=req.targetSystem,
        include_attachments=req.includeAttachments,
    )
    return ExportCreatedResponse(
        jobId=job_id,
        status=ExportJobStatus.QUEUED,
    )

async def get_export_status(job_id: str) -> ExportStatusResponse:
    job = jobs.get_job(job_id)
    if not job:
        raise KeyError(job_id)
    return ExportStatusResponse(
        jobId=job["jobId"],
        status=job["status"],
        statusUrl=f"/exports/{job_id}",
    )
