-- 025_house_reliability_checks.sql
-- Purpose: наш.дом.рф reliability check results scraped from Cian newbuilding pages.
--          Stores per-house check status and detail array.
-- Dependencies:
--   - houses table (009_houses.sql)
-- Deploy order: Apply after 024.
--
-- Sources: Schema_Cian_SERP_Inventory sec 16.4

BEGIN;

CREATE TABLE IF NOT EXISTS house_reliability_checks (
    id              bigserial   PRIMARY KEY,
    house_id        bigint      NOT NULL REFERENCES houses(id) ON DELETE CASCADE,
    check_status    text,                             -- 'reliable'/'problematic'/'unchecked'
    check_name      text,                             -- human-readable check name / title
    details         jsonb,                            -- [{type, title, iconType, ...}] raw checks array
    source          text        NOT NULL DEFAULT 'cian_nashdom',
    recorded_at     timestamptz NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS hrc_house_idx
  ON house_reliability_checks (house_id);

CREATE INDEX IF NOT EXISTS hrc_status_idx
  ON house_reliability_checks (check_status)
  WHERE check_status IS NOT NULL;

COMMIT;
