CREATE TABLE IF NOT EXISTS app.scenario_runs (
    scenario_run_id BIGSERIAL PRIMARY KEY,
    name TEXT NOT NULL,
    target_month TEXT NOT NULL CHECK (target_month ~ '^[0-9]{4}-[0-9]{2}$'),
    area_id TEXT REFERENCES silver.areas(area_id),
    interest_rate_delta_bps DOUBLE PRECISION NOT NULL DEFAULT 0,
    policy_signal_delta INTEGER NOT NULL DEFAULT 0 CHECK (policy_signal_delta BETWEEN -4 AND 4),
    supply_delta_pct DOUBLE PRECISION NOT NULL DEFAULT 0 CHECK (supply_delta_pct BETWEEN -100 AND 500),
    rent_delta_pct DOUBLE PRECISION NOT NULL DEFAULT 0 CHECK (rent_delta_pct BETWEEN -80 AND 200),
    notes TEXT NOT NULL DEFAULT '',
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_scenario_runs_month
    ON app.scenario_runs(target_month, scenario_run_id DESC);

CREATE INDEX IF NOT EXISTS idx_scenario_runs_area
    ON app.scenario_runs(area_id, scenario_run_id DESC);
