-- ******************************************************************
-- 表 kku_openapi_webhooks 的创建SQL
-- 对应的Model: App\Module\OpenAPI\Models\OpenApiWebhook
-- 警告: 此文件由系统自动生成，禁止修改！
-- ******************************************************************

CREATE TABLE `kku_openapi_webhooks` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `app_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '应用ID',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Webhook名称',
  `url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '回调URL',
  `events` json DEFAULT NULL COMMENT '监听的事件类型',
  `secret` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '签名密钥',
  `status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  `timeout` int NOT NULL DEFAULT '30' COMMENT '超时时间(秒)',
  `retry_count` int NOT NULL DEFAULT '3' COMMENT '重试次数',
  `current_retry_count` int NOT NULL DEFAULT '0' COMMENT '当前重试次数',
  `total_deliveries` int NOT NULL DEFAULT '0' COMMENT '总投递次数',
  `successful_deliveries` int NOT NULL DEFAULT '0' COMMENT '成功投递次数',
  `failed_deliveries` int NOT NULL DEFAULT '0' COMMENT '失败投递次数',
  `last_success_at` timestamp NULL DEFAULT NULL COMMENT '最后成功时间',
  `last_failure_at` timestamp NULL DEFAULT NULL COMMENT '最后失败时间',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_app_id` (`app_id`) USING BTREE,
  KEY `idx_status` (`status`) USING BTREE,
  KEY `idx_last_success_at` (`last_success_at`) USING BTREE,
  KEY `idx_last_failure_at` (`last_failure_at`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Webhook配置表';
