-- Add Adilo video columns to products table (webinars)
ALTER TABLE products
  ADD COLUMN IF NOT EXISTS m3u8_url TEXT,
  ADD COLUMN IF NOT EXISTS mp4_url TEXT,
  ADD COLUMN IF NOT EXISTS video_host TEXT DEFAULT 'youtube',
  ADD COLUMN IF NOT EXISTS adilo_video_id TEXT;

-- Add Adilo video columns to bootcamp_lessons table
ALTER TABLE bootcamp_lessons
  ADD COLUMN IF NOT EXISTS m3u8_url TEXT,
  ADD COLUMN IF NOT EXISTS mp4_url TEXT,
  ADD COLUMN IF NOT EXISTS video_host TEXT DEFAULT 'youtube',
  ADD COLUMN IF NOT EXISTS adilo_video_id TEXT;

-- Add constraint to ensure valid video hosts
ALTER TABLE products
  ADD CONSTRAINT products_video_host_check
  CHECK (video_host IN ('youtube', 'adilo'));

ALTER TABLE bootcamp_lessons
  ADD CONSTRAINT bootcamp_lessons_video_host_check
  CHECK (video_host IN ('youtube', 'adilo'));

-- Create indexes for faster queries
CREATE INDEX IF NOT EXISTS idx_products_video_host ON products(video_host);
CREATE INDEX IF NOT EXISTS idx_bootcamp_lessons_video_host ON bootcamp_lessons(video_host);

-- Comments for documentation
COMMENT ON COLUMN products.m3u8_url IS 'M3U8 streaming URL from Adilo for HLS playback';
COMMENT ON COLUMN products.mp4_url IS 'MP4 fallback URL from Adilo for direct download/legacy browsers';
COMMENT ON COLUMN products.video_host IS 'Video hosting platform: youtube or adilo';
COMMENT ON COLUMN products.adilo_video_id IS 'Adilo video identifier for API reference';

COMMENT ON COLUMN bootcamp_lessons.m3u8_url IS 'M3U8 streaming URL from Adilo for HLS playback';
COMMENT ON COLUMN bootcamp_lessons.mp4_url IS 'MP4 fallback URL from Adilo for direct download/legacy browsers';
COMMENT ON COLUMN bootcamp_lessons.video_host IS 'Video hosting platform: youtube or adilo';
COMMENT ON COLUMN bootcamp_lessons.adilo_video_id IS 'Adilo video identifier for API reference';
