-- ============================================================
-- FOMS / KTV产线服务 → Sage (uapi + llmage + pricing) 注册SQL
-- 供应商: 开元云（北京）科技有限公司
-- 服务器: opencomputing.net GPU集群
-- 所有 uapi response 均含 usage 字段用于自动计费
-- ============================================================

SET @provider_id = 'kaiyuanyun';
SET @owner_org = 'foms_org_001';

-- ============================================================
-- 1. llmcatelog — 模型类目 (新增KTV专用类目)
-- ============================================================
INSERT IGNORE INTO llmcatelog (id, name, description) VALUES
('ktv_pipeline',     'KTV产线',         'KTV视频制作全流程'),
('video_eval',       '视频评估',         'AI视频质量评估打分'),
('super_resolution', '超分辨率',         '图像/视频超分辨率增强'),
('asr',              '语音识别',         '自动语音识别转文字'),
('face_detect',      '人脸识别',         '人脸检测/识别/比对'),
('graph_process',    '图谱处理',         '知识图谱构建与查询'),
('ner',              '实体识别',         '命名实体识别'),
('song_eval',        '歌曲评分',         'AI歌曲质量评估'),
('music_gen',        '音乐生成',         'AI音乐/歌声合成'),
('audio_separate',   '音频分离',         '人声伴奏分离(Demucs)'),
('voice_convert',    '声音转换',         'RVC声音克隆/转换');

-- ============================================================
-- 2. llmprovider
-- ============================================================
INSERT IGNORE INTO llmprovider (id, name) VALUES
('kaiyuanyun', '开元云（北京）科技有限公司');

-- ============================================================
-- 3. upapp
-- ============================================================
INSERT IGNORE INTO upapp (id, name, baseurl, ownerid, auth_apiname) VALUES
('ktv-media-server',  'KTV媒体服务器',   'http://opencomputing.net:9080',  @owner_org, ''),
('ktv-video-eval',    'KTV视频评估',     'http://opencomputing.net:8901',  @owner_org, ''),
('ktv-realesrgan',    'KTV超分辨率',     'http://opencomputing.net:9082',  @owner_org, ''),
('ktv-asr',           'KTV语音识别',     'http://opencomputing.net:9925',  @owner_org, ''),
('ktv-face',          'KTV人脸识别',     'http://opencomputing.net:9091',  @owner_org, ''),
('ktv-graph',         'KTV图谱处理',     'http://opencomputing.net:9092',  @owner_org, ''),
('ktv-ner',           'KTV实体识别',     'http://opencomputing.net:9093',  @owner_org, ''),
('ktv-songrate',      'KTV歌曲评分',     'http://opencomputing.net:8900',  @owner_org, ''),
('ktv-synth',         'KTV音乐合成',     'http://opencomputing.net:9084',  @owner_org, ''),
('ktv-demucs',        'KTV音频分离',     'http://opencomputing.net:9083',  @owner_org, ''),
('ktv-rvc',           'KTV声音转换',     'http://opencomputing.net:9085',  @owner_org, '');

-- ============================================================
-- 4. llm
-- ============================================================
INSERT IGNORE INTO llm (id, name, model, providerid, ownerid, upappid, status) VALUES
('llm_ktv_pipeline',    'KTV产线流水线',    'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_video_eval',      'KTV视频评估',       'ktv-video-eval',      @provider_id, @owner_org, 'ktv-video-eval',    'published'),
('llm_realesrgan',      'KTV超分辨率增强',    'ktv-realesrgan',      @provider_id, @owner_org, 'ktv-realesrgan',    'published'),
('llm_asr',             'KTV语音识别ASR',     'ktv-asr',             @provider_id, @owner_org, 'ktv-asr',           'published'),
('llm_face',            'KTV人脸识别',        'ktv-face',            @provider_id, @owner_org, 'ktv-face',          'published'),
('llm_graph',           'KTV图谱处理',        'ktv-graph',           @provider_id, @owner_org, 'ktv-graph',         'published'),
('llm_ner',             'KTV命名实体识别',     'ktv-ner',             @provider_id, @owner_org, 'ktv-ner',           'published'),
('llm_songrate',        'KTV歌曲评分',        'ktv-songrate',        @provider_id, @owner_org, 'ktv-songrate',      'published'),
('llm_synth',           'KTV音乐合成',        'ktv-synth',           @provider_id, @owner_org, 'ktv-synth',         'published'),
('llm_demucs',          'KTV人声伴奏分离',     'ktv-demucs',          @provider_id, @owner_org, 'ktv-demucs',        'published'),
('llm_rvc',             'KTV声音克隆转换',     'ktv-rvc',             @provider_id, @owner_org, 'ktv-rvc',           'published'),
-- media-server 拆分为12个独立函数模型 (每个uapi端点一个llm)
('llm_ktv_pipe_status', 'KTV产线流水线状态',  'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_status',      'KTV媒体服务器状态',  'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_task',        'KTV任务查询',        'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_submit',      'KTV媒体提交',        'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_gen',         'KTV视频生成',        'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_demucs',      'KTV人声分离',        'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_subtitle',    'KTV字幕生成',        'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_calibrate',   'KTV校准',            'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_lyric_cal',   'KTV歌词校准',        'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_merge',       'KTV音视频合并',      'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
('llm_ktv_gpu_lock',    'KTV GPU锁定',        'ktv-media-server',    @provider_id, @owner_org, 'ktv-media-server',  'published'),
-- 其他服务补全端点
('llm_realesrgan_status','KTV超分状态',       'ktv-realesrgan',      @provider_id, @owner_org, 'ktv-realesrgan',    'published'),
('llm_face_recognize',  'KTV人脸识别',        'ktv-face',            @provider_id, @owner_org, 'ktv-face',          'published'),
('llm_face_compare',    'KTV人脸比对',        'ktv-face',            @provider_id, @owner_org, 'ktv-face',          'published'),
('llm_graph_add_node',  'KTV图谱加节点',      'ktv-graph',           @provider_id, @owner_org, 'ktv-graph',         'published'),
('llm_graph_add_edge',  'KTV图谱加边',        'ktv-graph',           @provider_id, @owner_org, 'ktv-graph',         'published'),
('llm_synth_status',    'KTV合成状态',        'ktv-synth',           @provider_id, @owner_org, 'ktv-synth',         'published');

-- ============================================================
-- 5. uapi — API端点 (所有 response 含 usage 计费字段)
-- ============================================================

-- 5.1 media-server (12 endpoints)
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('media-pipeline-submit',  'ktv-media-server', '/api/pipeline_submit/index.dspy',  'POST', '{"Content-Type":"application/json"}', '{"task_type":"{{task_type}}","params":{{json.dumps(params)}}}', '{"status":"ok","task_id":"{{task_id}}","usage":{"call_count":1}}', NULL),
('media-pipeline-status',  'ktv-media-server', '/api/pipeline_status/index.dspy',  'GET',  NULL, NULL, '{"status":"{{status}}","progress":{{progress}},"usage":{"call_count":1}}', NULL),
('media-status',           'ktv-media-server', '/api/status/index.dspy',            'GET',  NULL, NULL, '{"status":"ok","gpu_available":{{gpu_available}},"usage":{"call_count":1}}', NULL),
('media-task',             'ktv-media-server', '/api/task/index.dspy',              'GET',  NULL, NULL, '{"task_id":"{{task_id}}","status":"{{status}}","usage":{"call_count":1}}', NULL),
('media-submit',           'ktv-media-server', '/api/submit/index.dspy',            'POST', '{"Content-Type":"application/json"}', '{"video_url":"{{video_url}}","audio_url":"{{audio_url}}"}', '{"status":"ok","usage":{"call_count":1}}', NULL),
('media-ktv',              'ktv-media-server', '/api/ktv/index.dspy',              'POST', '{"Content-Type":"application/json"}', '{"song_name":"{{song_name}}","lyrics":"{{lyrics}}"}', '{"status":"ok","video_url":"{{video_url}}","usage":{"output_seconds":{{output_seconds}}}}', NULL),
('media-demucs',           'ktv-media-server', '/api/demucs/index.dspy',           'POST', '{"Content-Type":"application/json"}', '{"audio_url":"{{audio_url}}"}', '{"status":"ok","vocals_url":"{{vocals_url}}","accompaniment_url":"{{accompaniment_url}}","usage":{"audio_seconds":{{audio_seconds}}}}', NULL),
('media-subtitle',         'ktv-media-server', '/api/subtitle/index.dspy',          'POST', '{"Content-Type":"application/json"}', '{"lyrics":"{{lyrics}}","audio_url":"{{audio_url}}"}', '{"status":"ok","subtitle_url":"{{subtitle_url}}","usage":{"audio_seconds":{{audio_seconds}}}}', NULL),
('media-calibrate',        'ktv-media-server', '/api/calibrate/index.dspy',         'POST', '{"Content-Type":"application/json"}', '{"video_url":"{{video_url}}","audio_url":"{{audio_url}}"}', '{"status":"ok","offset":{{offset}},"usage":{"video_seconds":{{video_seconds}}}}', NULL),
('media-lyric-calibrate',  'ktv-media-server', '/api/lyric_calibrate/index.dspy',   'POST', '{"Content-Type":"application/json"}', '{"lyrics":"{{lyrics}}","audio_url":"{{audio_url}}"}', '{"status":"ok","calibrated_lyrics":"{{calibrated_lyrics}}","usage":{"audio_seconds":{{audio_seconds}}}}', NULL),
('media-merge',            'ktv-media-server', '/api/merge/index.dspy',             'POST', '{"Content-Type":"application/json"}', '{"video_url":"{{video_url}}","audio_url":"{{audio_url}}"}', '{"status":"ok","output_url":"{{output_url}}","usage":{"output_seconds":{{output_seconds}}}}', NULL),
('media-gpu-lock',         'ktv-media-server', '/api/gpu_lock/index.dspy',           'POST', '{"Content-Type":"application/json"}', '{"gpu_id":{{gpu_id}},"duration":{{duration}}}', '{"status":"ok","locked":true,"usage":{"call_count":1}}', NULL);

-- 5.2 video-eval
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('video-eval-evaluate', 'ktv-video-eval', '/api/eval/index.dspy', 'POST', '{"Content-Type":"application/json"}', '{"video_url":"{{video_url}}"}', '{"status":"ok","score":{{score}},"details":{{json.dumps(details)}},"usage":{"video_seconds":{{video_seconds}}}}', NULL);

-- 5.3 realesrgan
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('realesrgan-upscale',  'ktv-realesrgan', '/api/submit/index.dspy', 'POST', '{"Content-Type":"application/json"}', '{"image_url":"{{image_url}}","scale":{{scale}}}', '{"status":"ok","output_url":"{{output_url}}","usage":{"image_count":1}}', NULL),
('realesrgan-status',   'ktv-realesrgan', '/api/status/index.dspy', 'GET',  NULL, NULL, '{"status":"{{status}}","gpu_available":{{gpu_available}},"usage":{"call_count":1}}', NULL);

-- 5.4 asr
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('asr-transcribe', 'ktv-asr', '/api/transcribe/index.dspy', 'POST', '{"Content-Type":"application/json"}', '{"audio_url":"{{audio_url}}","language":"{{language}}"}', '{"status":"ok","text":"{{text}}","segments":{{json.dumps(segments)}},"usage":{"audio_seconds":{{audio_seconds}}}}', NULL);

-- 5.5 face
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('face-detect',    'ktv-face', '/api/detect',    'POST', '{"Content-Type":"application/json"}', '{"image_url":"{{image_url}}"}', '{"status":"ok","faces":{{json.dumps(faces)}},"usage":{"detect_count":1}}', NULL),
('face-recognize', 'ktv-face', '/api/recognize', 'POST', '{"Content-Type":"application/json"}', '{"image_url":"{{image_url}}","face_id":"{{face_id}}"}', '{"status":"ok","identity":"{{identity}}","confidence":{{confidence}},"usage":{"detect_count":1}}', NULL),
('face-compare',   'ktv-face', '/api/compare',   'POST', '{"Content-Type":"application/json"}', '{"image_url1":"{{url1}}","image_url2":"{{url2}}"}', '{"status":"ok","similarity":{{similarity}},"usage":{"detect_count":1}}', NULL);

-- 5.6 graph
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('graph-neighbors', 'ktv-graph', '/api/graph/neighbors', 'GET', NULL, NULL, '{"status":"ok","nodes":{{json.dumps(nodes)}},"usage":{"query_count":1}}', NULL),
('graph-add-node',  'ktv-graph', '/api/graph/add_node',  'POST', '{"Content-Type":"application/json"}', '{"node_id":"{{node_id}}","attrs":{{json.dumps(attrs)}}}', '{"status":"ok","usage":{"write_count":1}}', NULL),
('graph-add-edge',  'ktv-graph', '/api/graph/add_edge',  'POST', '{"Content-Type":"application/json"}', '{"from":"{{from}}","to":"{{to}}","label":"{{label}}"}', '{"status":"ok","usage":{"write_count":1}}', NULL);

-- 5.7 ner
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('ner-extract', 'ktv-ner', '/api/extract', 'POST', '{"Content-Type":"application/json"}', '{"text":"{{text}}"}', '{"status":"ok","entities":{{json.dumps(entities)}},"usage":{"char_count":{{char_count}}}}', NULL);

-- 5.8 songrate
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('songrate-evaluate', 'ktv-songrate', '/api/evaluate', 'POST', '{"Content-Type":"application/json"}', '{"audio_url":"{{audio_url}}","scene":"{{scene}}"}', '{"status":"ok","score":{{score}},"details":{{json.dumps(details)}},"usage":{"audio_seconds":{{audio_seconds}}}}', NULL);

-- 5.9 ktv-synth
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('synth-generate', 'ktv-synth', '/api/generate/index.dspy', 'POST', '{"Content-Type":"application/json"}', '{"lyrics":"{{lyrics}}","style":"{{style}}","reference_audio":"{{reference_audio}}"}', '{"status":"ok","task_id":"{{task_id}}","usage":{"output_seconds":{{output_seconds}}}}', NULL),
('synth-status',   'ktv-synth', '/api/status/index.dspy',   'GET',  NULL, NULL, '{"status":"{{status}}","audio_url":"{{audio_url}}","usage":{"call_count":1}}', NULL);

-- 5.10 demucs
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('demucs-separate', 'ktv-demucs', '/api/separate/index.dspy', 'POST', '{"Content-Type":"application/json"}', '{"audio_url":"{{audio_url}}"}', '{"status":"ok","vocals_url":"{{vocals_url}}","accompaniment_url":"{{accompaniment_url}}","usage":{"audio_seconds":{{audio_seconds}}}}', NULL);

-- 5.11 rvc
INSERT IGNORE INTO uapi (name, upappid, path, httpmethod, headers, data, response, ioid) VALUES
('rvc-convert', 'ktv-rvc', '/api/convert', 'POST', '{"Content-Type":"application/json"}', '{"audio_url":"{{audio_url}}","voice_model":"{{voice_model}}"}', '{"status":"ok","output_url":"{{output_url}}","usage":{"audio_seconds":{{audio_seconds}}}}', NULL);

-- ============================================================
-- 6. upappkey
-- ============================================================
INSERT IGNORE INTO upappkey (id, upappid, apikey, secretkey) VALUES
('key_ktv_media',  'ktv-media-server',  'ktv-media-key-001',  ''),
('key_ktv_eval',   'ktv-video-eval',    'ktv-eval-key-001',   ''),
('key_ktv_esrgan', 'ktv-realesrgan',    'ktv-esrgan-key-001', ''),
('key_ktv_asr',    'ktv-asr',           'ktv-asr-key-001',    ''),
('key_ktv_face',   'ktv-face',          'ktv-face-key-001',   ''),
('key_ktv_graph',  'ktv-graph',         'ktv-graph-key-001',  ''),
('key_ktv_ner',    'ktv-ner',           'ktv-ner-key-001',    ''),
('key_ktv_song',   'ktv-songrate',      'ktv-song-key-001',   ''),
('key_ktv_synth',  'ktv-synth',         'ktv-synth-key-001',  ''),
('key_ktv_demucs', 'ktv-demucs',        'ktv-demucs-key-001', ''),
('key_ktv_rvc',    'ktv-rvc',           'ktv-rvc-key-001',    '');

-- ============================================================
-- 7. llm_api_map
-- ============================================================
INSERT IGNORE INTO llm_api_map (id, llmid, llmcatelogid, apiname, isdefaultcatelog) VALUES
('map_ktv_pipeline', 'llm_ktv_pipeline', 'ktv_pipeline', 'media-pipeline-submit', '1'),
('map_video_eval',   'llm_video_eval',   'video_eval',   'video-eval-evaluate',  '1'),
('map_realesrgan',   'llm_realesrgan',   'super_resolution', 'realesrgan-upscale', '1'),
('map_asr',          'llm_asr',          'asr',          'asr-transcribe',       '1'),
('map_face_detect',  'llm_face',         'face_detect',  'face-detect',          '1'),
('map_graph',        'llm_graph',        'graph_process','graph-neighbors',      '1'),
('map_ner',          'llm_ner',          'ner',          'ner-extract',          '1'),
('map_songrate',     'llm_songrate',     'song_eval',    'songrate-evaluate',    '1'),
('map_synth',        'llm_synth',        'music_gen',    'synth-generate',       '1'),
('map_demucs',       'llm_demucs',       'audio_separate','demucs-separate',     '1'),
('map_rvc',          'llm_rvc',          'voice_convert', 'rvc-convert',         '1'),
-- media-server 拆分: 每个函数独立模型+API
('map_pipe_status',  'llm_ktv_pipe_status','ktv_pipeline','media-pipeline-status', '1'),
('map_media_st',     'llm_ktv_status',     'ktv_pipeline','media-status',          '1'),
('map_media_task',   'llm_ktv_task',       'ktv_pipeline','media-task',            '1'),
('map_media_submit', 'llm_ktv_submit',     'ktv_pipeline','media-submit',          '1'),
('map_media_ktv',    'llm_ktv_gen',        'ktv_pipeline','media-ktv',             '1'),
('map_media_demucs', 'llm_ktv_demucs',     'ktv_pipeline','media-demucs',          '1'),
('map_media_subt',   'llm_ktv_subtitle',   'ktv_pipeline','media-subtitle',        '1'),
('map_media_cal',    'llm_ktv_calibrate',  'ktv_pipeline','media-calibrate',       '1'),
('map_media_lyric',  'llm_ktv_lyric_cal',  'ktv_pipeline','media-lyric-calibrate', '1'),
('map_media_merge',  'llm_ktv_merge',      'ktv_pipeline','media-merge',           '1'),
('map_media_lock',   'llm_ktv_gpu_lock',   'ktv_pipeline','media-gpu-lock',        '1'),
-- 其他服务补全
('map_esrgan_st',    'llm_realesrgan_status','super_resolution','realesrgan-status','1'),
('map_face_rec',     'llm_face_recognize', 'face_detect',  'face-recognize',       '1'),
('map_face_cmp',     'llm_face_compare',   'face_detect',  'face-compare',         '1'),
('map_graph_add_n',  'llm_graph_add_node', 'graph_process', 'graph-add-node',      '1'),
('map_graph_add_e',  'llm_graph_add_edge', 'graph_process', 'graph-add-edge',      '1'),
('map_synth_st',     'llm_synth_status',   'music_gen',     'synth-status',        '1');

-- ============================================================
-- 8. pricing_program
-- ============================================================
INSERT IGNORE INTO pricing_program (id, name, ownerid, providerid, pricing_belong, discount, description) VALUES
('pp_ktv_pipeline',  'KTV产线流水线',      @owner_org, @provider_id, 'provider', 1.0, '按调用次数+产出时长'),
('pp_video_eval',    'KTV视频评估',        @owner_org, @provider_id, 'provider', 1.0, '按评估视频时长计费'),
('pp_realesrgan',    'KTV超分辨率增强',     @owner_org, @provider_id, 'provider', 1.0, '按处理图片张数计费'),
('pp_asr',           'KTV语音识别ASR',      @owner_org, @provider_id, 'provider', 1.0, '按音频秒数计费'),
('pp_face',          'KTV人脸识别',        @owner_org, @provider_id, 'provider', 1.0, '按检测次数计费'),
('pp_graph',         'KTV图谱处理',        @owner_org, @provider_id, 'provider', 1.0, '按读写次数计费'),
('pp_ner',           'KTV命名实体识别',     @owner_org, @provider_id, 'provider', 1.0, '按字符数计费'),
('pp_songrate',      'KTV歌曲评分',        @owner_org, @provider_id, 'provider', 1.0, '按音频秒数计费'),
('pp_synth',         'KTV音乐合成',        @owner_org, @provider_id, 'provider', 1.0, '按生成音频秒数计费'),
('pp_demucs',        'KTV人声伴奏分离',     @owner_org, @provider_id, 'provider', 1.0, '按音频秒数计费'),
('pp_rvc',           'KTV声音克隆转换',     @owner_org, @provider_id, 'provider', 1.0, '按音频秒数计费');

-- ============================================================
-- 9. pricing_program_timing — 定价时段
--    pricing_data 字段与 uapi response 中 usage 字段一一对应
-- ============================================================

-- KTV产线: 按次 + 按产出时长
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_ktv_pipeline',  'pp_ktv_pipeline',  '默认定价',
'unit_values:
  次: 1
  秒: 1
fields:
  call_count:
    type: int
    role: filter
    label: 调用次数
  output_seconds:
    type: float
    role: factor
    label: 产出时长(秒)
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: call_count
    unit_prices: 2.00
    unit: 次
  - price_factors: output_seconds
    unit_prices: 0.03
    unit: 秒', '2025-01-01');

-- video-eval: 按视频秒数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_video_eval',    'pp_video_eval',    '默认定价',
'unit_values:
  秒: 1
fields:
  video_seconds:
    type: float
    role: factor
    label: 视频时长(秒)
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: video_seconds
    unit_prices: 0.05
    unit: 秒', '2025-01-01');

-- realesrgan: 按图片张数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_realesrgan',    'pp_realesrgan',    '默认定价',
'unit_values:
  张: 1
fields:
  image_count:
    type: int
    role: factor
    label: 图片张数
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: image_count
    unit_prices: 0.50
    unit: 张', '2025-01-01');

-- asr: 按音频秒数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_asr',           'pp_asr',           '默认定价',
'unit_values:
  秒: 1
fields:
  audio_seconds:
    type: float
    role: factor
    label: 音频时长(秒)
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: audio_seconds
    unit_prices: 0.01
    unit: 秒', '2025-01-01');

-- face: 按检测次数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_face',          'pp_face',          '默认定价',
'unit_values:
  次: 1
fields:
  detect_count:
    type: int
    role: factor
    label: 检测次数
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: detect_count
    unit_prices: 0.10
    unit: 次', '2025-01-01');

-- graph: 按读写次数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_graph',         'pp_graph',         '默认定价',
'unit_values:
  次: 1
fields:
  query_count:
    type: int
    role: filter
    label: 查询次数
  write_count:
    type: int
    role: filter
    label: 写入次数
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: query_count
    unit_prices: 0.05
    unit: 次
  - price_factors: write_count
    unit_prices: 0.10
    unit: 次', '2025-01-01');

-- ner: 按字符数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_ner',           'pp_ner',           '默认定价',
'unit_values:
  千字: 1000
fields:
  char_count:
    type: int
    role: factor
    label: 字符数
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: char_count
    unit_prices: 0.50
    unit: 千字', '2025-01-01');

-- songrate: 按音频秒数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_songrate',      'pp_songrate',      '默认定价',
'unit_values:
  秒: 1
fields:
  audio_seconds:
    type: float
    role: factor
    label: 音频时长(秒)
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: audio_seconds
    unit_prices: 0.005
    unit: 秒', '2025-01-01');

-- ktv-synth: 按生成秒数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_synth',         'pp_synth',         '默认定价',
'unit_values:
  秒: 1
fields:
  output_seconds:
    type: float
    role: factor
    label: 生成时长(秒)
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: output_seconds
    unit_prices: 0.20
    unit: 秒', '2025-01-01');

-- demucs: 按音频秒数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_demucs',        'pp_demucs',        '默认定价',
'unit_values:
  秒: 1
fields:
  audio_seconds:
    type: float
    role: factor
    label: 音频时长(秒)
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: audio_seconds
    unit_prices: 0.02
    unit: 秒', '2025-01-01');

-- rvc: 按音频秒数
INSERT IGNORE INTO pricing_program_timing (id, ppid, name, pricing_data, enabled_date) VALUES
('ppt_rvc',           'pp_rvc',           '默认定价',
'unit_values:
  秒: 1
fields:
  audio_seconds:
    type: float
    role: factor
    label: 音频时长(秒)
  unit_prices:
    type: float
    role: factor
    label: 单位定价(元)
  unit:
    type: string
    role: factor
    label: 计价单位
pricings:
  - price_factors: audio_seconds
    unit_prices: 0.15
    unit: 秒', '2025-01-01');

-- ============================================================
-- 10. 绑定 ppid → llm_api_map
-- ============================================================
UPDATE llm_api_map SET ppid = 'pp_ktv_pipeline'  WHERE llmid = 'llm_ktv_pipeline';
UPDATE llm_api_map SET ppid = 'pp_video_eval'    WHERE llmid = 'llm_video_eval';
UPDATE llm_api_map SET ppid = 'pp_realesrgan'    WHERE llmid = 'llm_realesrgan';
UPDATE llm_api_map SET ppid = 'pp_asr'           WHERE llmid = 'llm_asr';
UPDATE llm_api_map SET ppid = 'pp_face'          WHERE llmid = 'llm_face';
UPDATE llm_api_map SET ppid = 'pp_graph'         WHERE llmid = 'llm_graph';
UPDATE llm_api_map SET ppid = 'pp_ner'           WHERE llmid = 'llm_ner';
UPDATE llm_api_map SET ppid = 'pp_songrate'      WHERE llmid = 'llm_songrate';
UPDATE llm_api_map SET ppid = 'pp_synth'         WHERE llmid = 'llm_synth';
UPDATE llm_api_map SET ppid = 'pp_demucs'        WHERE llmid = 'llm_demucs';
UPDATE llm_api_map SET ppid = 'pp_rvc'           WHERE llmid = 'llm_rvc';
