-- Junction table to link users (as personas) to a question_set (practice)
CREATE TABLE question_set_personas (
    id BIGSERIAL PRIMARY KEY,
    question_set_id BIGINT NOT NULL REFERENCES question_sets(id) ON DELETE CASCADE,
    user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    display_order INT DEFAULT 0,
    created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(question_set_id, user_id)
);

-- Add video context to question_sets for practice-video linking
ALTER TABLE question_sets
    ADD COLUMN sub_course_video_id BIGINT REFERENCES sub_course_videos(id) ON DELETE SET NULL;

-- Indexes
CREATE INDEX idx_question_set_personas_question_set_id ON question_set_personas(question_set_id);
CREATE INDEX idx_question_set_personas_user_id ON question_set_personas(user_id);
CREATE INDEX idx_question_sets_sub_course_video_id ON question_sets(sub_course_video_id);
