-- ============================================================================
-- P3·W-G1 派发面视觉终局·P2 兜底脚手架（gameId=9306 复用，RUNNING 任务供直接 POST succeeded 回调）
-- 缘由：主路#1(gen9306 whack)/#2(gen9307 tictactoe)两次真生成均栽于 driver-coverage——
--       design agent 给 driver:none、harness 盲打打不中目标→moves/score 恒 0→H_progress 挂(8/9 门过)，
--       repairs=5 仍未救回。【非模型壁垒】：游戏本体正确(targets/board/moves 全导出对、其余 8 门全过)，
--       缺的是 design agent 自产【适配性 tap-targets driver】(dispatch 面 run_studio(play_spec={}) 全恃 design agent)。
-- 兜底：取【已验证过九门】的样板 tictactoe(verdict.json A-I 全 pass)bundle.iife.js 作 engineBundle，
--       经派发面【真回调写链】(handleCallback·HMAC 验签·与真生成同代码路)落库入 feed。
--       【诚实标注】此款=便宜模型(flash)真生成的过九门游戏，仅非"本次一句话现生成"(本次现生成两次均卡 driver)。
-- 本脚本把 9306 重置：① 四态(project status=4/占位 version/pkg/feed_rank)；② 任务 status=1 RUNNING
--   (执行器仅 CAS 抢 QUEUED=0，status=1 不被抢；handleCallback 仅拒 final-failed，RUNNING 可接 succeeded 回调)。
-- trace_id='wg1-3bB-gen9306-fb-001'（与主路 gen9306-001 区分；回调 reqVO.traceId 须与此一致）
-- 用法：docker exec -i game-staging-mysql mysql --default-character-set=utf8mb4 -uroot -p"$MYSQL_ROOT_PASSWORD" < 本文件
-- ============================================================================
USE `ruoyi-vue-pro`;
SET NAMES utf8mb4;

START TRANSACTION;

DELETE FROM game_aigc_task         WHERE trace_id IN ('wg1-3bB-gen9306-001','wg1-3bB-gen9306-fb-001');
DELETE FROM game_feed_rank         WHERE game_id = 9306;
DELETE FROM game_runtime_package   WHERE game_id = 9306;
DELETE FROM game_version           WHERE game_id = 9306;
DELETE FROM game_project           WHERE id      = 9306;

-- ① project：已发布(status=4)，current_version_id 先指占位 93060（回调后 flip 翻到新版本 N）
INSERT INTO game_project
  (id, creator_user_id, title, summary, cover_url, tags, template_id, age_rating,
   status, current_version_id, launch_zone_id, featured, play_count, like_count,
   creator, create_time, updater, update_time, deleted, tenant_id)
VALUES
  (9306, 1, '井字棋(generic 兜底·已验证样板入feed)', 'P3 W-G1 视觉终局兜底：已过九门样板 tictactoe(便宜模型真生成) engineBundle 经派发面真回调链落库入 feed 真玩',
   'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
   'P3,3b-B,dispatch,generic,fallback,verified-tictactoe', 'generic', 'all',
   4, 93060, NULL, b'0', 0, 0, '0', NOW(), '0', NOW(), b'0', 0);

INSERT INTO game_version
  (id, game_id, version_no, gen_task_id, package_url, bundle_size, checksum,
   status, creator, create_time, updater, update_time, deleted, tenant_id)
VALUES (93060, 9306, 1, NULL, '', 0, '', 3, '0', NOW(), '0', NOW(), b'0', 0);

INSERT INTO game_runtime_package
  (id, game_id, version_id, template_id, package_url, entry, runtime_version, preload_policy,
   bundle_size, checksum, sandbox_attr, allow_origins, status,
   creator, create_time, updater, update_time, deleted, tenant_id, package_json)
VALUES (93060, 9306, 93060, 'generic', '', 'index.html', '1.0.0', 'eager',
   0, '', 'allow-scripts', '', 1, '0', NOW(), '0', NOW(), b'0', 0, NULL);

INSERT INTO game_feed_rank
  (id, game_id, version_id, zone_id, quality_score, boost, sort_score, pinned, status,
   creator, create_time, updater, update_time, deleted, tenant_id)
VALUES (93060, 9306, 93060, 0, 0.0000, 0.0000, 0.0000, 0, 1, '0', NOW(), '0', NOW(), b'0', 0);

-- ⑤ 任务 status=1 RUNNING（执行器不抢；供直接 POST succeeded 回调建版本/组包）
INSERT INTO game_aigc_task
  (creator_user_id, game_id, version_id, template_id, prompt, prompt_hash,
   status, progress, quality_score, failure_reason, result_package_url, retry_of, trace_id,
   creator, create_time, updater, update_time, finish_time, deleted, tenant_id)
VALUES
  (1, 9306, NULL, 'generic', '兜底:已验证样板 tictactoe 落 feed（便宜模型真生成过九门）',
   '0000000000000000000000000000000000000000000000000000000000009366',
   1, 50, NULL, '', '', NULL, 'wg1-3bB-gen9306-fb-001',
   '0', NOW(), '0', NOW(), NULL, b'0', 0);

COMMIT;

SELECT 'project' k, id, status, current_version_id FROM game_project WHERE id=9306
UNION ALL SELECT 'feed_rank', id, status, version_id FROM game_feed_rank WHERE id=93060;
SELECT 'aigc_task' k, id, status, game_id, trace_id FROM game_aigc_task WHERE trace_id='wg1-3bB-gen9306-fb-001';
