-- Shows / Series
CREATE TABLE shows (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  creator_id uuid NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
  title text NOT NULL,
  description text,
  cover_url text,
  created_at timestamptz NOT NULL DEFAULT now()
);

ALTER TABLE shows ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Anyone can view shows"
  ON shows FOR SELECT
  USING (true);

CREATE POLICY "Creators can manage their own shows"
  ON shows FOR ALL
  USING (creator_id = auth.uid())
  WITH CHECK (creator_id = auth.uid());

-- Add show_id to podcasts
ALTER TABLE podcasts ADD COLUMN show_id uuid REFERENCES shows(id) ON DELETE SET NULL;

CREATE INDEX idx_podcasts_show ON podcasts(show_id) WHERE show_id IS NOT NULL;
