-- Migration: sales_rebuttals
-- Date: 2026-01-28
-- Description: Simple objections + responses for sales scripts

-- Create table
CREATE TABLE IF NOT EXISTS sales_rebuttals (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  title TEXT NOT NULL,
  response TEXT NOT NULL,
  category VARCHAR(100),
  tags TEXT[] DEFAULT '{}',
  created_at TIMESTAMPTZ DEFAULT NOW(),
  updated_at TIMESTAMPTZ DEFAULT NOW()
);

-- Indexes
CREATE INDEX IF NOT EXISTS idx_sales_rebuttals_category ON sales_rebuttals(category);
CREATE INDEX IF NOT EXISTS idx_sales_rebuttals_tags ON sales_rebuttals USING GIN(tags);

-- RLS
ALTER TABLE sales_rebuttals ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Authenticated users can view rebuttals"
  ON sales_rebuttals FOR SELECT TO authenticated USING (true);

CREATE POLICY "Authenticated users can manage rebuttals"
  ON sales_rebuttals FOR ALL TO authenticated
  USING (true) WITH CHECK (true);

CREATE POLICY "Service role full access"
  ON sales_rebuttals FOR ALL TO service_role
  USING (true) WITH CHECK (true);
