from __future__ import annotations from uuid import UUID from pydantic import Field, model_validator from .common import ApiEnvelope, JsonObject, JsonValue, RouteContract, SchemaModel HTTP_METHOD = 'POST' ROUTE_PATH = '/api/crop-simulation/growth/' class CropSimulationGrowthRequest(SchemaModel): plant_name: str dynamic_parameters: list[str] = Field(min_length=1) farm_uuid: UUID | None = None weather: JsonValue | None = None soil_parameters: JsonObject | None = None site_parameters: JsonObject | None = None crop_parameters: JsonObject | None = None agromanagement: JsonObject | None = None page_size: int | None = Field(default=None, ge=1, le=50) @model_validator(mode='after') def validate_farm_or_weather(self) -> 'CropSimulationGrowthRequest': if self.farm_uuid is None and self.weather is None: raise ValueError('Either farm_uuid or weather must be provided.') return self class CropSimulationGrowthResponseData(SchemaModel): task_id: str status_url: str plant_name: str class CropSimulationGrowthResponse(ApiEnvelope[CropSimulationGrowthResponseData]): pass CONTRACT = RouteContract( method=HTTP_METHOD, path=ROUTE_PATH, request_model=CropSimulationGrowthRequest.__name__, response_model=CropSimulationGrowthResponse.__name__, )