-- Per-bar condition audit for rule-based backtest runs.
-- Only populated when RunConfig::audit_conditions = true.
-- One row per (bar, rule), with the full condition tree stored as a JSONB array.
CREATE TABLE paper_run_condition_audit (
    id          BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    run_id      UUID NOT NULL REFERENCES paper_runs(id) ON DELETE CASCADE,
    bar_index   INTEGER NOT NULL,
    bar_time    TIMESTAMPTZ NOT NULL,
    rule_index  SMALLINT NOT NULL,
    rule_fired  BOOLEAN NOT NULL,
    conditions  JSONB NOT NULL
);

CREATE INDEX idx_condition_audit_run ON paper_run_condition_audit(run_id, bar_index);
