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

CREATE TABLE `kku_thirdparty_logs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `service_id` bigint unsigned NOT NULL COMMENT '服务ID',
  `credential_id` bigint unsigned DEFAULT NULL COMMENT '凭证ID',
  `request_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '请求ID（用于追踪）',
  `method` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '请求方法',
  `url` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '请求URL',
  `headers` json DEFAULT NULL COMMENT '请求头',
  `params` json DEFAULT NULL COMMENT '请求参数',
  `body` text COLLATE utf8mb4_unicode_ci COMMENT '请求体',
  `response_status` int DEFAULT NULL COMMENT '响应状态码',
  `response_headers` json DEFAULT NULL COMMENT '响应头',
  `response_body` text COLLATE utf8mb4_unicode_ci COMMENT '响应体',
  `response_time` int DEFAULT NULL COMMENT '响应时间（毫秒）',
  `error_message` text COLLATE utf8mb4_unicode_ci COMMENT '错误信息',
  `level` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'INFO' COMMENT '日志级别',
  `user_id` bigint unsigned DEFAULT NULL COMMENT '用户ID',
  `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'IP地址',
  `user_agent` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'User Agent',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_service_id` (`service_id`),
  KEY `idx_credential_id` (`credential_id`),
  KEY `idx_request_id` (`request_id`),
  KEY `idx_method` (`method`),
  KEY `idx_response_status` (`response_status`),
  KEY `idx_level` (`level`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_created_at` (`created_at`),
  CONSTRAINT `fk_logs_credential` FOREIGN KEY (`credential_id`) REFERENCES `kku_thirdparty_credentials` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_logs_service` FOREIGN KEY (`service_id`) REFERENCES `kku_thirdparty_services` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='调用日志表';
