-- ============================================
-- AutoMail Pro v6 — Supabase Table Setup
-- Colar e executar em: supabase.com → SQL Editor
-- ============================================

CREATE TABLE IF NOT EXISTS brands (
  id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
  name text NOT NULL,
  country text,
  website text,
  email text,
  categories text,
  positioning text,
  avg_price numeric,
  price_segment text,
  analysis_status text,
  analysis_summary text,
  source text,
  hubspot_exists boolean DEFAULT false,
  hubspot_company_id text,
  notes text,
  created_at timestamptz DEFAULT now(),
  updated_at timestamptz DEFAULT now()
);

-- Índice único para evitar duplicados (mesma marca + país)
CREATE UNIQUE INDEX IF NOT EXISTS brands_name_country_idx 
  ON brands(LOWER(name), LOWER(COALESCE(country, '')));

-- Permitir acesso via API (anon key)
ALTER TABLE brands ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Allow all operations" ON brands 
  FOR ALL USING (true) WITH CHECK (true);
