[
  {
    "type": "create_table",
    "description": "Create chat_sms_usage table for Two-Way SMS Chat billing and analytics",
    "database": "{{central}}",
    "check_query": "SHOW TABLES LIKE 'chat_sms_usage'",
    "sql": "CREATE TABLE `chat_sms_usage` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `typeNum` varchar(20) NOT NULL COMMENT 'Store identifier',\n  `thread_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Reference to chat_threads in store DB',\n  `message_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Reference to chat_messages in store DB',\n  `direction` enum('inbound','outbound') NOT NULL COMMENT 'Message direction',\n  `category` enum('transactional','interactive') NOT NULL COMMENT 'Message category for billing',\n  `provider` enum('vonage','twilio') NOT NULL COMMENT 'SMS provider used',\n  `provider_message_id` varchar(255) DEFAULT NULL COMMENT 'External message ID from provider',\n  `segment_count` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT 'Number of SMS segments',\n  `cost_per_segment` decimal(10,4) NOT NULL DEFAULT 0.0000 COMMENT 'Cost per segment at time of send',\n  `total_cost` decimal(10,4) NOT NULL DEFAULT 0.0000 COMMENT 'Total cost for this message',\n  `billable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Whether this message is billable',\n  `sent_at` timestamp NOT NULL COMMENT 'When message was sent',\n  `billing_period` varchar(7) NOT NULL COMMENT 'YYYY-MM format for billing aggregation',\n  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),\n  PRIMARY KEY (`id`),\n  KEY `idx_typenum_period` (`typeNum`, `billing_period`),\n  KEY `idx_billable` (`typeNum`, `billable`, `billing_period`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Two-Way SMS Chat usage tracking for billing and analytics'"
  }
]
