"""Response models for API endpoints""" from pydantic import BaseModel, Field from typing import List, Optional from datetime import datetime class Product(BaseModel): """Individual product model""" id: str = Field(..., description="Product ID") name: str = Field(..., description="Product name") price: str = Field(..., description="Product price") url: str = Field(..., description="Product URL") image_url: Optional[str] = Field(None, description="Product image URL") class ScrapeResponse(BaseModel): """Response model for scraping endpoint""" success: bool = Field(..., description="Whether the scraping was successful") search_term: str = Field(..., description="Search term used") total_expected: Optional[int] = Field(None, description="Total products expected") total_extracted: int = Field(..., description="Total products extracted") extraction_rate: Optional[float] = Field(None, description="Extraction success rate (%)") products: List[Product] = Field(..., description="List of extracted products") execution_time: float = Field(..., description="Execution time in seconds") timestamp: datetime = Field(default_factory=datetime.now, description="Timestamp of extraction") error: Optional[str] = Field(None, description="Error message if failed") model_config = { "json_schema_extra": { "example": { "success": True, "search_term": "bags", "total_expected": 200, "total_extracted": 198, "extraction_rate": 99.0, "products": [ { "id": "product_001", "name": "Birkin 25", "price": "1,500,000 JPY", "url": "https://www.hermes.com/jp/ja/product/...", "image_url": "https://assets.hermes.com/..." } ], "execution_time": 35.2, "timestamp": "2025-01-24T10:00:00", "error": None } } } class HealthResponse(BaseModel): """Health check response""" status: str = Field(..., description="Service status") version: str = Field(..., description="API version") uptime: float = Field(..., description="Uptime in seconds") timestamp: datetime = Field(default_factory=datetime.now)