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

CREATE TABLE `kku_thirdparty_credentials` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `service_id` bigint unsigned NOT NULL COMMENT '服务ID',
  `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '凭证名称',
  `type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '凭证类型',
  `credentials` json NOT NULL COMMENT '凭证信息（加密存储）',
  `environment` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'production' COMMENT '环境（production/staging/development）',
  `is_active` tinyint(1) DEFAULT '1' COMMENT '是否激活',
  `expires_at` timestamp NULL DEFAULT NULL COMMENT '过期时间',
  `last_used_at` timestamp NULL DEFAULT NULL COMMENT '最后使用时间',
  `usage_count` bigint DEFAULT '0' COMMENT '使用次数',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_service_id` (`service_id`),
  KEY `idx_type` (`type`),
  KEY `idx_environment` (`environment`),
  KEY `idx_is_active` (`is_active`),
  KEY `idx_expires_at` (`expires_at`),
  CONSTRAINT `fk_credentials_service` FOREIGN KEY (`service_id`) REFERENCES `kku_thirdparty_services` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='认证凭证表';
