from __future__ import annotations from datetime import datetime from typing import Literal from uuid import UUID from pydantic import BaseModel, model_validator from app.schemas.operations import VectorSelectionBBox ExportKind = Literal["dataset", "detection_run", "segmentation_run", "vector_selection"] class GeoJsonExportRequest(BaseModel): dataset_id: UUID | None = None analysis_run_id: UUID | None = None export_kind: ExportKind = "dataset" name: str | None = None bbox: VectorSelectionBBox | None = None limit: int = 250 @model_validator(mode="after") def validate_target(self) -> "GeoJsonExportRequest": if self.export_kind == "dataset" and self.dataset_id is None: raise ValueError("dataset_id is required for dataset GeoJSON exports") if self.export_kind == "vector_selection": if self.dataset_id is None: raise ValueError("dataset_id is required for vector selection GeoJSON exports") if self.bbox is None: raise ValueError("bbox is required for vector selection GeoJSON exports") if self.export_kind in {"detection_run", "segmentation_run"} and self.analysis_run_id is None: raise ValueError("analysis_run_id is required for run GeoJSON exports") return self class MetadataExportRequest(BaseModel): project_id: UUID name: str | None = None class ReportExportRequest(BaseModel): project_id: UUID name: str | None = None class ExportRead(BaseModel): id: UUID project_id: UUID analysis_run_id: UUID | None = None export_type: str storage_path: str metadata_json: dict | None = None created_at: datetime | None = None status: str = "ready" model_config = {"from_attributes": True} class ExportCreateResponse(BaseModel): export_id: UUID path: str status: str export_type: str metadata_json: dict | None = None class ExportListResponse(BaseModel): items: list[ExportRead] total: int limit: int offset: int class ExportContentResponse(BaseModel): export_id: UUID export_type: str content: dict