51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""Pydantic schemas for Trade-In Estimator.
|
|
|
|
POST /api/v1/trade-in/estimate → AggregatedEstimate
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import date, datetime
|
|
from typing import Literal
|
|
from uuid import UUID
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class TradeInEstimateInput(BaseModel):
|
|
address: str = Field(min_length=3, max_length=500)
|
|
area_m2: float = Field(gt=10, lt=500)
|
|
rooms: int = Field(ge=0, le=10) # 0 = студия
|
|
floor: int = Field(ge=1, le=100)
|
|
total_floors: int = Field(ge=1, le=100)
|
|
year_built: int | None = Field(default=None, ge=1800, le=2100)
|
|
house_type: Literal["panel", "brick", "monolith", "monolith_brick", "other"] | None = None
|
|
repair_state: Literal["needs_repair", "standard", "good", "excellent"] | None = None
|
|
has_balcony: bool | None = None
|
|
|
|
|
|
class AnalogLot(BaseModel):
|
|
address: str
|
|
area_m2: float
|
|
rooms: int
|
|
floor: int | None
|
|
total_floors: int | None
|
|
price_rub: int
|
|
price_per_m2: int
|
|
listing_date: date | None
|
|
days_on_market: int | None
|
|
photo_url: str | None = None
|
|
|
|
|
|
class AggregatedEstimate(BaseModel):
|
|
estimate_id: UUID
|
|
median_price_rub: int
|
|
range_low_rub: int
|
|
range_high_rub: int
|
|
median_price_per_m2: int
|
|
confidence: Literal["low", "medium", "high"]
|
|
n_analogs: int
|
|
period_months: int # 24
|
|
analogs: list[AnalogLot] # top 5-10 listings
|
|
actual_deals: list[AnalogLot] # реальные продажи last 12 mo
|
|
expires_at: datetime
|