-- Leads Table for Supabase
-- Run in SQL Editor

CREATE TABLE IF NOT EXISTS leads (
  id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
  user_id TEXT DEFAULT 'default',
  name TEXT NOT NULL,
  business_name TEXT,
  phone TEXT,
  email TEXT,
  source TEXT,
  status TEXT DEFAULT 'new' CHECK (status IN ('new', 'contacted', 'qualified', 'won', 'lost')),
  notes TEXT,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_leads_user ON leads(user_id);
CREATE INDEX IF NOT EXISTS idx_leads_status ON leads(status);

-- Sample leads
INSERT INTO leads (name, business_name, phone, status, source) VALUES
('Juan García', 'Restaurante La Niña', '+34 952 449 193', 'new', 'cold_call'),
('María López', 'Clínica Dental Málaga', '+34 951 123 456', 'contacted', 'website'),
('Carlos Ruiz', 'Inmobiliaria Costa', '+34 600 123 456', 'qualified', 'referral');

-- Disable RLS for now
ALTER TABLE leads DISABLE ROW LEVEL SECURITY;
