"""Category request / response schemas.""" from __future__ import annotations from datetime import datetime from typing import Optional from pydantic import BaseModel, Field class CategoryBase(BaseModel): name: str = Field(..., min_length=1, max_length=100) description: str = Field(..., min_length=1, max_length=500) icon: str = Field(default="tag", max_length=50) slug: str = Field(..., min_length=1, max_length=100, pattern="^[a-z0-9]+(?:-[a-z0-9]+)*$") class CategoryCreate(CategoryBase): pass class CategoryUpdate(BaseModel): name: Optional[str] = Field(None, min_length=1, max_length=100) description: Optional[str] = Field(None, min_length=1, max_length=500) icon: Optional[str] = Field(None, max_length=50) slug: Optional[str] = Field(None, min_length=1, max_length=100, pattern="^[a-z0-9]+(?:-[a-z0-9]+)*$") class CategoryResponse(BaseModel): id: str name: str description: str icon: str slug: str listing_count: int = 0 created_at: datetime updated_at: Optional[datetime] = None model_config = {"from_attributes": True} class CategoryListResponse(BaseModel): categories: list[CategoryResponse] total: int