SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

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

-- 仅在首次把旧分支迁入配置时保留 Huwaa 已上线的全区域行为；运行时只读取当前 App 的配置，
-- 未配置 App 仍 fail closed 为 viewer_region，新增租户不会继承其他产品的跨区域范围。
INSERT INTO admin_app_configs (app_code, `group`, `key`, value, description, is_deleted, created_at_ms, updated_at_ms)
VALUES ('huwaa', 'room-discovery', 'scope', 'all_active_regions', '房间发现范围：viewer_region 或 all_active_regions', 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-room-discovery', '/app-config/room-discovery', 'public', 'app-config:view', 72, 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);
