-- Source accuracy tracking table for historical prediction accuracy per source.
--
-- Stores per-source accuracy metrics (fraction of correct directional calls)
-- used by the probabilistic scoring pipeline to weight source credibility.
-- See Requirement 4.5: source accuracy metrics stored with source identifier,
-- accuracy ratio, sample count, and last updated timestamp.

CREATE TABLE IF NOT EXISTS source_accuracy (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    source_id VARCHAR(200) NOT NULL,
    accuracy_ratio FLOAT NOT NULL DEFAULT 0.5,
    sample_count INTEGER NOT NULL DEFAULT 0,
    last_updated TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    UNIQUE(source_id)
);

CREATE INDEX IF NOT EXISTS idx_source_accuracy_source ON source_accuracy(source_id);
