-- =====================================================
-- TABLE: education.review_helpful_votes
-- =====================================================
-- Proyecto: OrbiQuant IA (Trading Platform)
-- Módulo: OQI-002 - Education
-- Especificación: Votos de "útil" en reviews de cursos
-- =====================================================

CREATE TABLE education.review_helpful_votes (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),

  user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
  review_id UUID NOT NULL REFERENCES education.course_reviews(id) ON DELETE CASCADE,

  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),

  CONSTRAINT unique_user_review_vote UNIQUE(user_id, review_id)
);

-- Índices
CREATE INDEX idx_review_helpful_votes_user ON education.review_helpful_votes(user_id);
CREATE INDEX idx_review_helpful_votes_review ON education.review_helpful_votes(review_id);

-- Comentarios
COMMENT ON TABLE education.review_helpful_votes IS 'Votos de usuarios que encontraron útil una review';
COMMENT ON CONSTRAINT unique_user_review_vote ON education.review_helpful_votes IS 'Un usuario solo puede votar una vez por review';
