CREATE TABLE IF NOT EXISTS sessions (
  session_id VARCHAR(16) PRIMARY KEY,
  current_url TEXT,
  current_title TEXT,
  initial_url TEXT,
  initial_title TEXT,
  previous_url TEXT,
  previous_title TEXT,
  initial_utm_json TEXT,
  initial_click_id VARCHAR(255),
  call_extension VARCHAR(8) UNIQUE,
  call_extension_assigned_at TIMESTAMP NULL DEFAULT NULL,
  call_extension_expires_at TIMESTAMP NULL DEFAULT NULL,
  agent_allowed TINYINT(1) DEFAULT 1,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- Optional audit log (nice-to-have; can skip for day-1)
CREATE TABLE IF NOT EXISTS audit (
  id INT AUTO_INCREMENT PRIMARY KEY,
  session_id VARCHAR(16),
  seq BIGINT,
  type VARCHAR(50),
  selector TEXT,
  allowed TINYINT(1) DEFAULT 1,
  notes TEXT,
  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX (session_id), INDEX (seq)
);
