SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

SET @now_ms = CAST(UNIX_TIMESTAMP(UTC_TIMESTAMP(3)) * 1000 AS UNSIGNED);

-- 这些行只是在首次引入通用能力配置时保存旧产品行为；运行时只按当前 App 的配置值决策，
-- 未配置 App 的默认值仍是 app_global + legacy_optional，不需要在 Go/JS 中维护产品名单。
INSERT INTO admin_app_configs (app_code, `group`, `key`, value, description, is_deleted, created_at_ms, updated_at_ms)
VALUES
  ('lalu', 'runtime-capabilities', 'activity_leaderboard_scope', 'viewer_region', '活动榜单范围：app_global 或 viewer_region', FALSE, @now_ms, @now_ms),
  ('fami', 'runtime-capabilities', 'activity_leaderboard_scope', 'viewer_region', '活动榜单范围：app_global 或 viewer_region', FALSE, @now_ms, @now_ms),
  ('fami', 'runtime-capabilities', 'resource_equip_command_id_policy', 'required', '资源佩戴幂等键策略：legacy_optional 或 required', FALSE, @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE id = id;

INSERT INTO admin_menus (parent_id, title, code, path, icon, permission_code, sort, visible, created_at_ms, updated_at_ms)
SELECT parent.id, '运行能力配置', 'app-config-runtime-capabilities', '/app-config/runtime-capabilities', 'settings', 'app-config:view', 73, TRUE, @now_ms, @now_ms
FROM admin_menus parent
WHERE parent.code = 'app-config'
ON DUPLICATE KEY UPDATE
  parent_id = VALUES(parent_id),
  title = VALUES(title),
  path = VALUES(path),
  icon = VALUES(icon),
  permission_code = VALUES(permission_code),
  sort = VALUES(sort),
  visible = VALUES(visible),
  updated_at_ms = VALUES(updated_at_ms);
