CREATE TABLE IF NOT EXISTS leads (
  id INT AUTO_INCREMENT PRIMARY KEY,
  caller VARCHAR(20) NOT NULL UNIQUE,
  whatsapp VARCHAR(20) DEFAULT NULL,
  website_type VARCHAR(100) DEFAULT NULL,
  budget VARCHAR(100) DEFAULT NULL,
  room_number VARCHAR(100) DEFAULT NULL,
  notes TEXT DEFAULT NULL,
  last_call DATETIME DEFAULT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS call_sessions (
  id INT AUTO_INCREMENT PRIMARY KEY,
  caller VARCHAR(20) NOT NULL,
  turns INT DEFAULT 0,
  silence_count INT DEFAULT 0,
  started_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  ended_at DATETIME DEFAULT NULL,
  active TINYINT(1) DEFAULT 1,
  INDEX(caller)
);

CREATE TABLE IF NOT EXISTS chat_messages (
  id INT AUTO_INCREMENT PRIMARY KEY,
  caller VARCHAR(20) NOT NULL,
  role ENUM('system','user','assistant') NOT NULL,
  content TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  INDEX(caller)
);
