"""Schemas for CDEK order registration.""" from typing import Literal from pydantic import BaseModel, ConfigDict, Field, model_validator class OrderPhone(BaseModel): number: str = Field(min_length=1) class OrderParty(BaseModel): model_config = ConfigDict(extra="forbid") name: str = Field(min_length=1) email: str = Field(min_length=1) phone: OrderPhone @model_validator(mode="before") @classmethod def reject_company_field(cls, value: object) -> object: if isinstance(value, dict) and "company" in value: raise ValueError("company is not allowed") return value class OrderLocation(BaseModel): address: str = Field(min_length=1) city: str = Field(min_length=1) country_code: str = Field(min_length=2, max_length=2) class OrderService(BaseModel): code: str = Field(min_length=1) parameter: str = Field(min_length=1) class OrderPackage(BaseModel): number: str = Field(min_length=1) weight: int = Field(gt=0) length: int = Field(gt=0) width: int = Field(gt=0) height: int = Field(gt=0) comment: str | None = None class OrderCreateRequest(BaseModel): type: Literal[2] tariff_code: Literal[535] comment: str | None = None sender: OrderParty recipient: OrderParty from_location: OrderLocation to_location: OrderLocation services: list[OrderService] | None = Field(default=None, min_length=1) packages: list[OrderPackage] = Field(min_length=1) class OrderCreateResponse(BaseModel): provider: str = Field(min_length=1) order_uuid: str = Field(min_length=1)