// Trade-In Estimator — TypeScript types
// Mirrors Pydantic schemas from backend/app/api/v1/trade_in.py (TI-1)

export type HouseType =
  | "panel"
  | "brick"
  | "monolith"
  | "monolith_brick"
  | "other";

export type RepairState = "needs_repair" | "standard" | "good" | "excellent";

export type ConfidenceLevel = "low" | "medium" | "high";

export interface TradeInEstimateInput {
  address: string; // min 3, max 500
  area_m2: number; // 10 < x < 500
  rooms: number; // 0-10 (0 = студия)
  floor: number; // 1-100
  total_floors: number; // 1-100
  year_built?: number; // 1800-2100
  house_type?: HouseType;
  repair_state?: RepairState;
  has_balcony?: boolean;
}

export interface AnalogLot {
  address: string;
  area_m2: number;
  rooms: number;
  floor: number | null;
  total_floors: number | null;
  price_rub: number;
  price_per_m2: number;
  listing_date: string | null; // ISO date
  days_on_market: number | null;
  photo_url: string | null;
}

export interface AggregatedEstimate {
  estimate_id: string; // UUID
  median_price_rub: number;
  range_low_rub: number;
  range_high_rub: number;
  median_price_per_m2: number;
  confidence: ConfidenceLevel;
  n_analogs: number;
  period_months: number; // 24
  analogs: AnalogLot[]; // top 5-10
  actual_deals: AnalogLot[]; // last 12 mo
  expires_at: string; // ISO datetime
}
