-- ============================================================
-- MiniMax-H3 Video Generation — UAPI + Pricing 完整部署 SQL
-- 执行方式: 在 Sage 管理面板或 MySQL 客户端执行
-- ============================================================

-- === 1. uapiio (输入输出定义) ===
INSERT IGNORE INTO uapiio (id, name, description, input_fields) VALUES (
  'm_h3_video_gen_io',
  'MiniMax-H3 视频生成',
  'MiniMax-H3 视频生成v2接口输入输出定义。支持文生视频、图生视频(首尾帧)、多模态参考生视频。',
  '{"model":{"type":"string","required":true,"title":"模型名称","enum":["MiniMax-H3"]},"content":{"type":"array","required":true,"title":"多模态输入内容"},"resolution":{"type":"string","required":true,"title":"分辨率","enum":["768P","2K"]},"duration":{"type":"integer","required":true,"title":"时长(秒)","enum":[4,5,6,7,8,9,10,11,12,13,14,15]},"ratio":{"type":"string","title":"宽高比","enum":["adaptive","21:9","16:9","4:3","1:1","3:4","9:16"]},"callback_url":{"type":"string","title":"回调地址"},"aigc_watermark":{"type":"boolean","title":"AIGC水印"}}'
);

-- === 2. uapi - 创建视频任务 ===
INSERT IGNORE INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
  'm_h3_create_task', 'minimax', 'video_generation_v2',
  'MiniMax-H3 创建视频任务',
  '创建 MiniMax-H3 视频生成任务。返回 task_id，用查询接口轮询结果。',
  '0', 'async', '/v2/video_generation', 'POST', 'task_id',
  '{"Content-Type":"application/json","Authorization":"Bearer {{apikey}}"}',
  NULL, '{{jsondata}}', '{{response}}', 'm_h3_video_gen_io'
);

-- === 3. uapi - 查询视频任务 ===
INSERT IGNORE INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
  'm_h3_query_task', 'minimax', 'query_video_generation',
  'MiniMax-H3 查询视频任务',
  '按 task_id 查询 MiniMax-H3 视频生成任务状态与结果。',
  '0', 'sync', '/v2/query/video_generation/{{task_id}}', 'GET', '',
  '{"Authorization":"Bearer {{apikey}}"}',
  NULL, NULL, '{{response}}', 'm_h3_video_gen_io'
);

-- === 4. upapp - 平台注册 ===
INSERT IGNORE INTO upapp (id, name, baseurl, myappid, ownerid, description) VALUES (
  'minimax', 'minimax', 'https://api.minimax.chat', 'minimax', 'platform',
  'MiniMax 视频生成平台。提供 H3 视频生成模型，支持文生视频、图生视频、多模态参考生视频。'
);

-- === 5. upappkey - API密钥 (请替换为真实key) ===
-- INSERT IGNORE INTO upappkey (id, upappid, orgid, apikey, enabled_date, expired_date) VALUES (
--   'mk_minimax_default', 'minimax', 'platform', '<RC4_ENCODED_API_KEY>', '2025-01-01', '9999-12-31'
-- );

-- ============================================================
-- === 6. Pricing - 定价方案 ===
-- ============================================================
INSERT IGNORE INTO pricing_program (id, name, description, unit, unit_price, currency, category, provider, model, resolution) VALUES (
  'minimax_h3_2k', 'MiniMax-H3-2K', 'MiniMax-H3 2K分辨率视频生成，按秒计费',
  'second', 0.80, 'CNY', 'video_generation', 'minimax', 'MiniMax-H3', '2K'
);

INSERT IGNORE INTO pricing_program (id, name, description, unit, unit_price, currency, category, provider, model, resolution) VALUES (
  'minimax_h3_768p', 'MiniMax-H3-768P', 'MiniMax-H3 768P分辨率视频生成，按秒计费',
  'second', 0.50, 'CNY', 'video_generation', 'minimax', 'MiniMax-H3', '768P'
);

-- ============================================================
-- === 7. RBAC - 注册权限 (可选, DSPY已存于uapi仓库) ===
-- ============================================================
-- INSERT IGNORE INTO permission (id, path, name) VALUES ('perm_minimax_setup', '/uapi/api/minimax_h3_setup.dspy', 'MiniMax-H3 Setup');
-- INSERT IGNORE INTO rolepermission (id, permid, roleid) VALUES ('rp_minimax_setup', 'perm_minimax_setup', 'any');
