-- docs/MIGRATIONS_PHONE_CLICKS.sql
-- Phone-Click Tracking Table

CREATE TABLE IF NOT EXISTS phone_clicks (
  id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  phone_number TEXT NOT NULL,
  source_page TEXT NOT NULL,
  source_element TEXT NOT NULL,
  session_id TEXT,
  ip_anonymized TEXT,
  country TEXT,
  region TEXT,
  city TEXT,
  device_type TEXT,
  browser TEXT,
  os TEXT,
  user_agent TEXT,
  is_bot BOOLEAN DEFAULT false,
  timestamp TIMESTAMPTZ DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_phone_clicks_timestamp ON phone_clicks(timestamp DESC);
CREATE INDEX IF NOT EXISTS idx_phone_clicks_phone_number ON phone_clicks(phone_number);
CREATE INDEX IF NOT EXISTS idx_phone_clicks_source_page ON phone_clicks(source_page);
CREATE INDEX IF NOT EXISTS idx_phone_clicks_source_element ON phone_clicks(source_element);
CREATE INDEX IF NOT EXISTS idx_phone_clicks_country ON phone_clicks(country);

-- RLS (Row Level Security) deaktivieren für Admin-Zugriff
ALTER TABLE phone_clicks DISABLE ROW LEVEL SECURITY;
