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="The title of the todo item" ) description: Optional[str] = Field( None, description="An optional detailed description of the todo item" ) completed: bool = Field( False, description="Whether the todo item has been 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 to allow partial updates. """ title: Optional[str] = Field( None, min_length=1, max_length=255, description="The title of the todo item" ) description: Optional[str] = Field( None, description="An optional detailed description of the todo item" ) completed: Optional[bool] = Field( None, description="Whether the todo item has been completed" ) class TodoInDBBase(TodoBase): """ Schema for Todo items as stored in the database. """ id: int created_at: datetime updated_at: datetime class Config: from_attributes = True class Todo(TodoInDBBase): """ Schema for Todo items returned to the client. """ pass class TodoList(BaseModel): """ Schema for a list of Todo items. """ items: list[Todo] count: int