from datetime import datetime from typing import Optional from pydantic import BaseModel, Field class TodoBase(BaseModel): """Base schema for Todo items with common attributes.""" title: str = Field(..., min_length=1, max_length=255, description="Title of the todo item") description: Optional[str] = Field(None, description="Detailed description of the todo item") completed: bool = Field(False, description="Whether the todo item is completed") class TodoCreate(TodoBase): """Schema for creating a new Todo item.""" pass class TodoUpdate(BaseModel): """Schema for updating an existing Todo item. All fields are optional.""" title: Optional[str] = Field(None, min_length=1, max_length=255, description="Title of the todo item") description: Optional[str] = Field(None, description="Detailed description of the todo item") completed: Optional[bool] = Field(None, description="Whether the todo item is completed") class TodoResponse(TodoBase): """Schema for Todo item responses, including database fields.""" id: int created_at: datetime updated_at: Optional[datetime] = None class Config: """Configure Pydantic model to work with SQLAlchemy models.""" from_attributes = True