SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE DATABASE IF NOT EXISTS hyapp_game DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

USE hyapp_game;

-- 自研游戏数据单独维护；schema 初始化只建表，默认数据在这里保证 dice 和 rock 在新环境中同时可用。
SET @now_ms := CAST(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000 AS UNSIGNED);
SET @self_game_stakes := CAST('[{"StakeCoin":100,"Enabled":true,"SortOrder":10},{"StakeCoin":500,"Enabled":true,"SortOrder":20},{"StakeCoin":1000,"Enabled":true,"SortOrder":30},{"StakeCoin":8000,"Enabled":true,"SortOrder":40}]' AS JSON);

INSERT INTO game_platforms (
  app_code, platform_code, platform_name, status, api_base_url, adapter_type,
  callback_secret_ciphertext, callback_ip_whitelist, adapter_config,
  sort_order, created_at_ms, updated_at_ms
) VALUES (
  'lalu', 'dice', 'Dice Internal', 'active', '', 'dice_internal',
  '', CAST('[]' AS JSON), CAST('{}' AS JSON),
  0, @now_ms, @now_ms
) ON DUPLICATE KEY UPDATE updated_at_ms = updated_at_ms;

INSERT INTO game_catalog (
  app_code, game_id, platform_code, provider_game_id, game_name, category, icon_url, cover_url,
  launch_mode, orientation, safe_height, min_coin, status, sort_order, tags, created_at_ms, updated_at_ms
) VALUES
  ('lalu', 'dice', 'dice', 'dice', 'Dice', 'self', '', '', 'h5_popup', 'portrait', 0, 0, 'active', 0, CAST('["self_game"]' AS JSON), @now_ms, @now_ms),
  ('lalu', 'rock', 'dice', 'rock', 'Rock Paper Scissors', 'self', '', '', 'h5_popup', 'portrait', 0, 0, 'active', 1, CAST('["self_game"]' AS JSON), @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE updated_at_ms = updated_at_ms;

INSERT INTO game_display_rules (
  app_code, rule_id, game_id, scene, region_id, language, platform, visible, enabled, sort_order, created_at_ms, updated_at_ms
) VALUES
  ('lalu', 'dice_voice_default', 'dice', 'voice_room', 0, '', '', 1, 1, 0, @now_ms, @now_ms),
  ('lalu', 'rock_voice_default', 'rock', 'voice_room', 0, '', '', 1, 1, 1, @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE updated_at_ms = updated_at_ms;

INSERT INTO game_self_game_configs (
  app_code, game_id, status, stake_options_json, fee_bps, pool_bps,
  min_players, max_players, robot_enabled, robot_match_wait_ms, created_at_ms, updated_at_ms
) VALUES
  ('lalu', 'dice', 'active', @self_game_stakes, 500, 100, 2, 2, 1, 1000, @now_ms, @now_ms),
  ('lalu', 'rock', 'active', @self_game_stakes, 500, 100, 2, 2, 1, 1000, @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE updated_at_ms = updated_at_ms;

INSERT INTO game_self_game_pools (app_code, game_id, balance_coin, created_at_ms, updated_at_ms)
VALUES
  ('lalu', 'dice', 0, @now_ms, @now_ms),
  ('lalu', 'rock', 0, @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE updated_at_ms = updated_at_ms;
