-- 077_create_live_streams.sql
-- Live streams metadata (Phase 3 - Coming Soon features)

CREATE TABLE IF NOT EXISTS public.live_streams (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,

    title VARCHAR(200) NOT NULL,
    description TEXT,
    category VARCHAR(100) DEFAULT '',
    thumbnail_url VARCHAR(500),
    stream_key VARCHAR(100) NOT NULL DEFAULT '',
    streamer_name VARCHAR(100) NOT NULL DEFAULT '',

    is_live BOOLEAN NOT NULL DEFAULT false,
    started_at TIMESTAMPTZ,
    ended_at TIMESTAMPTZ,
    viewer_count INT NOT NULL DEFAULT 0,
    tags JSONB DEFAULT '[]',

    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_live_streams_user_id ON public.live_streams(user_id);
CREATE INDEX IF NOT EXISTS idx_live_streams_is_live ON public.live_streams(is_live) WHERE is_live = true;

COMMENT ON TABLE public.live_streams IS 'Live stream metadata - actual streaming via Stream Server';
