from datetime import datetime from typing import Optional from pydantic import BaseModel, Field class TodoBase(BaseModel): """Base Todo schema with common attributes""" title: str = Field(..., min_length=1, max_length=100, description="Title of the todo") description: Optional[str] = Field( None, max_length=500, description="Detailed description of the todo", ) completed: bool = Field(False, description="Whether the todo is completed") class TodoCreate(TodoBase): """Schema for creating a new todo""" pass class TodoUpdate(BaseModel): """Schema for updating an existing todo, all fields are optional""" title: Optional[str] = Field( None, min_length=1, max_length=100, description="Title of the todo", ) description: Optional[str] = Field( None, max_length=500, description="Detailed description of the todo", ) completed: Optional[bool] = Field(None, description="Whether the todo is completed") class TodoResponse(TodoBase): """Schema for todo response that includes database fields""" id: int created_at: datetime updated_at: Optional[datetime] = None class Config: """ORM mode config for the TodoResponse schema""" orm_mode = True from_attributes = True