-- version: 4
-- SP6 T2: 999 rejection tracking + state-history index for the Done-today lane.

ALTER TABLE claims ADD COLUMN rejection_reason TEXT;
ALTER TABLE claims ADD COLUMN rejected_at TIMESTAMP;
ALTER TABLE claims ADD COLUMN resubmit_count INTEGER NOT NULL DEFAULT 0;
ALTER TABLE claims ADD COLUMN state_changed_at TIMESTAMP;

CREATE INDEX ix_claims_state_changed_at ON claims(state, state_changed_at);