-- 玩家管理：新增“获取游戏链接”按钮权限

SET @now = NOW();

-- 优先使用已有“数据列表”按钮找到玩家菜单 ID
SET @player_menu_id = (
  SELECT `parent_id` FROM `sa_system_menu`
  WHERE `slug` = 'dice:player:index:index' AND `type` = 3
  ORDER BY `id` ASC LIMIT 1
);

-- 兜底：按玩家菜单路径查找
SET @player_menu_id = IFNULL(
  @player_menu_id,
  (
    SELECT `id` FROM `sa_system_menu`
    WHERE `path` = 'player' AND `type` = 2
    ORDER BY `id` ASC LIMIT 1
  )
);

INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT @player_menu_id, '获取游戏链接', '', 'dice:player:index:getGameUrl', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE @player_menu_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:player:index:getGameUrl' AND `type` = 3
  );
