from datetime import date from typing import List, Optional from pydantic import BaseModel, Field, field_validator class ApproachUpdate(BaseModel): weight: float = Field(ge=0) reps: int = Field(gt=0) class ExerciseUpdate(BaseModel): name: str = Field(max_length=255) splitted_weight: bool = False approaches: List[ApproachUpdate] = Field(default_factory=list) @field_validator("name") @classmethod def strip_name(cls, value: str) -> str: value = value.strip() if not value: raise ValueError("name must not be empty") return value class TrainingUpdate(BaseModel): """The whole training as it should be after the edit (PUT replaces it).""" date: date trainee_id: int trainer_id: Optional[int] = None # None: a solo training exercises: List[ExerciseUpdate] = Field(default_factory=list)