-- Stores deduplicated strategy definitions, identified by a content hash of their
-- signal logic (excluding instrument, candle interval, position sizing, and execution context).
-- Each paper run links to its strategy via paper_runs.strategy_id.
CREATE TABLE strategies (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    hash        TEXT NOT NULL UNIQUE,
    config      JSONB NOT NULL,        -- full strategy config as submitted (includes candle_interval etc.)
    hash_input  JSONB NOT NULL,        -- normalized JSON used to compute hash (for verification)
    created_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX idx_strategies_hash ON strategies(hash);

ALTER TABLE paper_runs
    ADD COLUMN strategy_id UUID REFERENCES strategies(id);
