-- Runtime state is generic JSON so future widget and relation renderers can
-- persist interaction-specific state without adding a column per widget kind.
ALTER TABLE osint.playthrough_widget_state
ADD COLUMN config JSONB NOT NULL DEFAULT '{}'::jsonb;

CREATE TABLE osint.playthrough_widget_relation_state (
  playthrough_id TEXT NOT NULL REFERENCES osint.playthroughs(id) ON DELETE CASCADE,
  relation_id TEXT NOT NULL REFERENCES osint.widget_relations(id) ON DELETE CASCADE,
  config JSONB NOT NULL DEFAULT '{}'::jsonb,
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  PRIMARY KEY (playthrough_id, relation_id)
);

COMMENT ON COLUMN osint.playthrough_widget_state.config IS 'Player-owned runtime and metadata overrides for any authored widget type';
COMMENT ON TABLE osint.playthrough_widget_relation_state IS 'Player-owned layout/state overrides for authored widget relations';
