CREATE TABLE IF NOT EXISTS `mod_fusionpbx_ai_tenants` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(255) NOT NULL,
  `whmcs_client_id` INT(11) NOT NULL,
  `api_key` VARCHAR(255) DEFAULT NULL,
  `voice` VARCHAR(50) DEFAULT 'female',
  PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `mod_fusionpbx_ai_ivrs` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `tenant_id` INT(11) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `greeting` TEXT,
  `fallback_extension` VARCHAR(50),
  `business_hours` JSON,
  PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `mod_fusionpbx_ai_calls` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `tenant_id` INT(11) NOT NULL,
  `ivr_id` INT(11) DEFAULT NULL,
  `caller_number` VARCHAR(50),
  `transcript` TEXT,
  `status` VARCHAR(50),
  `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `mod_fusionpbx_ai_analytics` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `tenant_id` INT(11) NOT NULL,
  `metric` VARCHAR(255) NOT NULL,
  `value` INT NOT NULL,
  `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
);
