-- Add tour_selected_id to leads table for tracking which tour was selected
ALTER TABLE leads ADD COLUMN IF NOT EXISTS tour_selected_id UUID REFERENCES tours(id) ON DELETE SET NULL;

-- Update trigger_source check constraint to include 'ai_route_recommendation'
ALTER TABLE leads DROP CONSTRAINT IF EXISTS leads_trigger_source_check;
ALTER TABLE leads ADD CONSTRAINT leads_trigger_source_check 
  CHECK (trigger_source IN ('save_modal', 'planner_cta', 'contextual_banner', 'ai_route_recommendation'));

-- Create index for tour_selected_id
CREATE INDEX IF NOT EXISTS idx_leads_tour_selected_id ON leads(tour_selected_id);