
-- Table to log address searches
CREATE TABLE public.search_logs (
  id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
  search_term TEXT NOT NULL,
  selected_address_id TEXT,
  selected_address_formatted TEXT,
  fiber_available BOOLEAN,
  max_speed INTEGER,
  contact_email TEXT,
  contact_phone TEXT,
  created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
);

-- Enable RLS
ALTER TABLE public.search_logs ENABLE ROW LEVEL SECURITY;

-- Allow anonymous inserts (public facing feature, no auth required)
CREATE POLICY "Anyone can insert search logs"
  ON public.search_logs
  FOR INSERT
  WITH CHECK (true);

-- Only backend/admin can read logs
CREATE POLICY "No public read on search logs"
  ON public.search_logs
  FOR SELECT
  USING (false);
