-- API Keys for authentication
CREATE TABLE IF NOT EXISTS `api_keys` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `api_key` VARCHAR(255) NOT NULL UNIQUE,
  `is_active` BOOLEAN NOT NULL DEFAULT TRUE,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Webhook request logs
CREATE TABLE IF NOT EXISTS `webhook_logs` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `endpoint` VARCHAR(255) NOT NULL,
  `request_headers` TEXT,
  `request_body` LONGTEXT,
  `response_status` INT,
  `ip_address` VARCHAR(45),
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- AI Call Logs
CREATE TABLE IF NOT EXISTS `ai_call_logs` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `call_id` VARCHAR(255) NOT NULL UNIQUE,
    `conversation_id` VARCHAR(255) DEFAULT NULL,
    `call_start_time` DATETIME NOT NULL,
    `call_end_time` DATETIME DEFAULT NULL,
    `call_duration_seconds` INT DEFAULT NULL,
    `call_intent` VARCHAR(100) DEFAULT NULL,
    `call_outcome` VARCHAR(100) DEFAULT NULL,
    `ai_summary` TEXT,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Call Tracking Logs
CREATE TABLE IF NOT EXISTS `call_tracking` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `external_call_id` VARCHAR(255) NOT NULL,
    `tracking_platform` VARCHAR(100) NOT NULL,
    `call_start_time` DATETIME NOT NULL,
    `call_status` VARCHAR(50) NOT NULL,
    `traffic_source` VARCHAR(100),
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Reviews
CREATE TABLE IF NOT EXISTS `reviews` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `platform_source` VARCHAR(100) NOT NULL,
    `star_rating` DECIMAL(3, 2) NOT NULL,
    `review_text` TEXT,
    `reviewer_name` VARCHAR(255),
    `review_date` DATETIME,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
