-- Enable pg_trgm for fast LIKE/ILIKE queries
CREATE EXTENSION IF NOT EXISTS pg_trgm;

-- Trigram indexes for articles title/content (case-insensitive search)
CREATE INDEX IF NOT EXISTS idx_articles_title_trgm ON articles USING gin (lower(title) gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_articles_content_trgm ON articles USING gin (lower(content) gin_trgm_ops);

-- Email logs composite index to accelerate recipient history lookups
CREATE INDEX IF NOT EXISTS idx_email_logs_recipient_created ON email_logs (recipient_email, created_at DESC);

-- Email events quick filter by type
CREATE INDEX IF NOT EXISTS idx_email_events_type ON email_events (event_type);

-- Newsletter sent log frequency by type and time
CREATE INDEX IF NOT EXISTS idx_newsletter_sent_log_type_time ON newsletter_sent_log (newsletter_type, sent_at DESC);

-- Match notifications lookups by match and type
CREATE INDEX IF NOT EXISTS idx_match_notifications_match_type ON match_notifications (match_id, notification_type);

-- Blog notifications listing by sent time
CREATE INDEX IF NOT EXISTS idx_blog_notifications_sent_at ON blog_notifications (sent_at DESC);
