Files
service-finder/backend/app/schemas/analytics.py
2026-03-13 10:22:41 +00:00

46 lines
2.1 KiB
Python

"""
Analytics Pydantic schemas for TCO (Total Cost of Ownership) API responses.
"""
from typing import List, Optional, Dict, Any
from pydantic import BaseModel, Field
class TCOResponse(BaseModel):
"""Response schema for a single TCO category breakdown."""
category_id: int = Field(..., description="Cost category ID")
category_code: str = Field(..., description="Category code (e.g., 'FUEL', 'MAINTENANCE')")
category_name: str = Field(..., description="Human-readable category name")
amount: float = Field(..., description="Total amount in original currency")
currency: str = Field(..., description="Original currency code (e.g., 'EUR', 'HUF')")
amount_huf: float = Field(..., description="Amount converted to HUF")
percentage: float = Field(..., description="Percentage of total cost (0-100)")
class Config:
from_attributes = True
class TCOSummaryStats(BaseModel):
"""Statistics part of the TCO summary."""
total_cost: float = Field(..., description="Total cost in HUF")
cost_per_km: Optional[float] = Field(None, description="Cost per kilometer (HUF/km)")
total_transactions: int = Field(..., description="Number of cost transactions")
date_range: Optional[Dict[str, str]] = Field(None, description="Start and end dates if filtered")
class TCOSummaryResponse(BaseModel):
"""Complete TCO summary for a vehicle."""
vehicle_id: int = Field(..., description="Vehicle ID")
user_tco: List[TCOResponse] = Field(..., description="TCO breakdown for the current user/organization")
lifetime_tco: List[TCOResponse] = Field(..., description="Lifetime TCO across all owners (anonymized)")
benchmark_tco: List[TCOResponse] = Field(..., description="Benchmark TCO for similar vehicles")
stats: TCOSummaryStats = Field(..., description="Aggregated statistics")
class Config:
from_attributes = True
class TCOErrorResponse(BaseModel):
"""Error response for TCO endpoints."""
detail: str = Field(..., description="Error description")
vehicle_id: Optional[int] = Field(None, description="Related vehicle ID if applicable")