// TypeScript shapes for the /trade-in/v2 design fixtures.
// All values are sample/markup data (see fixtures.ts) — no API types here.

export interface Report {
  id: string;
  date: string;
  validUntil: string;
}

export interface ObjectInfo {
  address: string;
  city: string;
  area: string;
  rooms: string;
  floor: string;
  totalFloors: string;
  year: string;
  houseType: string;
  repair: string;
  balcony: boolean;
  // Compact HeroBar badge for the location index (see mapObject / mappers.ts
  // locationIndexBadge): "+12%"/"−8%" when the backend has a reliable value
  // (status="ok"), else a short honest reason ("вне ЕКБ" / "мало данных" /
  // "нет данных" while loading) — never a fabricated percent.
  locationIndexLabel: string;
  // true only when locationIndexLabel is a real percent (status="ok") — tells
  // HeroBar whether to render it as the accent numeric value or as the muted
  // unavailable-reason pill.
  locationIndexOk: boolean;
  // Subject coordinates for the HeroBar locator mini-map (Leaflet/OSM). null
  // when the estimate has no geocode yet — the map then renders an honest
  // "нет координат" placeholder instead of an empty/broken box.
  lat: number | null;
  lon: number | null;
}

// ---- 02 RESULT ------------------------------------------------------------

export interface ResultCard {
  /** Header label, one entry per visual line. */
  title: string[];
  /** Big mono number, e.g. "11,29". */
  value: string;
  /** Unit suffix, e.g. "млн ₽". */
  unit: string;
  /** Low — high range line, e.g. "7,72 — 14,46 млн ₽". */
  range: string;
  /** ₽/м² sub-line (may include a "· N сделки" tail). */
  ppm: string;
  /** Mini-histogram column heights in % (cards 1 & 3). */
  bars?: number[];
  /** Delta value, e.g. "−18%" (card 2). Rendered as a calm pill, not a gauge. */
  delta?: string;
  /** Delta pill caption, e.g. "к цене объявления" (card 2). */
  deltaLabel?: string;
  /** Reconciliation note under the value (card 2: expected price vs ДКП median). */
  note?: string;
  /** H1 empty-state message: when set (card 2, no expected-sold prediction) the
   *  card renders this instead of value/range/ppm/delta, and the panel moves the
   *  accent frame onto the «рекомендованная цена» card. */
  emptyNote?: string;
  /** Nav index opened by the card's "Подробнее →" link. */
  nav: number;
}

export interface ResultMeta {
  sources: string;
  confidence: string;
  cv: string;
  /** Data-driven footer provenance, e.g. "ПОСТРОЕНО ПО 6 АНАЛОГАМ И 10 СДЕЛКАМ". */
  builtOn?: string;
  /**
   * Fix #1 (audit) — the ИСТОЧНИКИ ДАННЫХ tile counts are summed from the
   * persisted top-10 analogs/deals sample (backend #2087 M1: source_counts is
   * deliberately computed from the SAME capped list as `analogs`, to stay
   * consistent across POST/GET), so they can undercount vs. builtOn's real
   * n_analogs total for large result sets. e.g. "Разбивка — по показанным 10
   * из 37 аналогам" so the two numbers on this card never read as one total.
   */
  sourcesNote?: string;
}

export interface RangeMarker {
  /** Filled segment offsets / dot position, as CSS % strings. */
  fillLeft: string;
  fillRight: string;
  dotLeft: string;
}

export interface RangeBar {
  /** Header label, one entry per visual line. */
  label: string[];
  median: string;
  lo: string;
  hi: string;
  marker: RangeMarker;
}

export interface Ranges {
  ads: RangeBar;
  deals: RangeBar;
}

export interface ScatterPoint {
  x: number;
  y: number;
  r: number;
}

export interface AxisTickX {
  label: string;
  x: number;
}

export interface AxisTickY {
  label: string;
  y: number;
}

export interface ScatterMini {
  deals: ScatterPoint[];
  analogs: ScatterPoint[];
  subject: ScatterPoint;
  yTicks: AxisTickY[];
  xTicks: AxisTickX[];
}

export interface SourceCard {
  name: string;
  /** Lot count, e.g. "7" or "—" when no data. */
  count: string;
  /** Count caption: "лотов" / "лот" / "нет данных". */
  label: string;
  active: boolean;
}

// ---- 03 SUMMARY -----------------------------------------------------------

export interface SummaryRow {
  label: string;
  value: string;
  dot: "accent" | "muted";
  nav: number;
}

export interface SummaryQuality {
  sources: string;
  confidence: string;
  cv: string;
}

export interface Summary {
  rows: SummaryRow[];
  quality: SummaryQuality;
}

// ---- OVERLAY: ПРОДАЖИ В ДОМЕ / ИСТОРИЯ ------------------------------------

export interface DkpRow {
  area: string;
  price: string;
  ppm: string;
  ask: string;
  delta: string;
  /** Colour for the delta (success / danger token value). */
  deltaColor: string;
}

export interface HouseSaleRow {
  lot: string;
  priceFrom: string;
  priceTo: string;
  date: string;
  exposure: string;
}

export interface History {
  houseSales: HouseSaleRow[];
  dkpHeader: { title: string; period: string; note: string };
  dkpKpi: { count: string; median: string; range: string };
}

// ---- OVERLAY: АНАЛОГИЧНЫЕ ОБЪЯВЛЕНИЯ --------------------------------------

export interface AdRow {
  addr: string;
  meta: string;
  ppm: string;
  price: string;
}

export interface DealRow {
  addr: string;
  meta: string;
  ppm: string;
  price: string;
}

export interface MarketAds {
  kpi: {
    count: string;
    median: string;
    ppm: string;
    range: string;
    cv: string;
  };
  filters: string[];
}

export interface MarketDeals {
  kpi: { count: string; median: string; delta: string; range: string };
}

// ---- OVERLAY: АНАЛИТИКА ДОМА ----------------------------------------------

export interface AnalyticsKpi {
  label: string;
  value: string;
  unit?: string;
  /** Optional value colour override (token value). */
  color?: string;
  sub: string;
}

export interface SellTimeTier {
  tier: string;
  days: string;
  range: string;
  count: string;
  variant: "success" | "accent" | "gold" | "danger";
  /** Backend-flagged bucket too thin to trust (see SellTimeBucket.insufficient_data). */
  insufficientData?: boolean;
}

export interface PriceHistory {
  note: string;
  years: string[];
  /** SVG polyline points string (viewBox 0 0 900 220). */
  avito: string;
  yandex: string;
  /** Y-axis tick labels + pixel y, recomputed for the data-driven ₽/м² domain. */
  yTicks: AxisTickY[];
}

export interface ScatterDetail {
  note: string;
  deals: ScatterPoint[];
  analogs: ScatterPoint[];
  subject: ScatterPoint;
  /** True when subject.x is a fallback (est_days_on_market unknown), not a real value. */
  subjectApprox?: boolean;
  yTicks: AxisTickY[];
  xTicks: AxisTickX[];
}

export interface Analytics {
  header: { ads: string; radius: string };
  kpis: AnalyticsKpi[];
  sellTime: SellTimeTier[];
  /** Sub-line above the sell-time tiers (carries the эталон ₽/м² number). */
  sellTimeNote: string;
  priceHistory: PriceHistory;
  scatterDetail: ScatterDetail;
}

// ---- OVERLAY: ПРЕДЫДУЩИЕ ОЦЕНКИ (CACHE) -----------------------------------

export interface CacheRow {
  /** Estimate UUID — needed to navigate to the full report on row click (#2420). */
  id: string;
  addr: string;
  time: string;
  src: string;
  status: string;
  /** Status dot/text colour (success / warn / danger token value). */
  statusColor: string;
  /** Pre-formatted compact summary, e.g. "2 комн · 54 м² · 5/9 эт." (#2420). */
  params: string;
}

export interface CacheKpi {
  label: string;
  value: string;
  unit?: string;
  sub: string;
}

// ---- INPUTS / DROPDOWNS ---------------------------------------------------

export interface DropdownOptions {
  rooms: string[];
  houseType: string[];
  repair: string[];
  radius: string[];
  crm: string[];
}

// Note: the pre-wiring `LocationFactor`/`LocationFactors` types (base/coef/
// result formula + positives/negatives) lived here — removed together with
// the location-index rewrite: LocationDrawer now consumes `LocationData`
// (see ./mappers.ts), which reflects the real backend contract, not the old
// fabricated formula.

// ---- USER / CHROME --------------------------------------------------------

export interface User {
  name: string;
  org: string;
  email: string;
  initials: string;
  reports: number;
}
