-- Admin AI scene: image_recognition

INSERT INTO admin_ai_scene (scene_code, scene_name, scene_type, pipeline_type, quality_threshold, status, create_by, update_by)
SELECT 'image_recognition', '图片识别(多模态)', 'single', NULL, NULL, 1, 'system', 'system'
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM admin_ai_scene WHERE scene_code = 'image_recognition');

INSERT INTO admin_ai_scene_model (scene_code, model_id, pipeline_order, role, sort_weight)
SELECT 'image_recognition', m.id,
       ROW_NUMBER() OVER (ORDER BY m.sort_order, m.id) - 1,
       'generator', 0
FROM admin_ai_model m
WHERE m.status = 1
  AND (
    LOWER(m.model_identifier) LIKE '%vision%'
    OR LOWER(m.model_identifier) LIKE '%vl%'
    OR LOWER(m.model_identifier) LIKE 'qwen-vl%'
    OR LOWER(m.model_identifier) LIKE 'hunyuan-vision%'
  )
  AND NOT EXISTS (
    SELECT 1 FROM admin_ai_scene_model sm
    WHERE sm.scene_code = 'image_recognition' AND sm.model_id = m.id
  );

INSERT INTO admin_ai_model (model_name, provider_code, model_identifier, api_endpoint, api_key, max_tokens, temperature, sort_order, status, create_by, update_by)
SELECT '通义千问VL(Qwen-VL)', 'qwen', 'qwen-vl-plus',
       'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions', '',
       4096, 0.7, 20, 0, 'system', 'system'
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM admin_ai_model WHERE provider_code = 'qwen' AND model_identifier = 'qwen-vl-plus');

INSERT INTO admin_ai_model (model_name, provider_code, model_identifier, api_endpoint, api_key, max_tokens, temperature, sort_order, status, create_by, update_by)
SELECT '混元视觉(Hunyuan-Vision)', 'yuanbao', 'hunyuan-vision',
       'https://api.hunyuan.cloud.tencent.com/v1/chat/completions', '',
       4096, 0.7, 21, 0, 'system', 'system'
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM admin_ai_model WHERE provider_code = 'yuanbao' AND model_identifier = 'hunyuan-vision');

INSERT INTO admin_ai_model (model_name, provider_code, model_identifier, api_endpoint, api_key, max_tokens, temperature, sort_order, status, create_by, update_by)
SELECT '豆包视觉(Doubao-Vision)', 'doubao', 'doubao-1-5-thinking-vision-pro-250428',
       'https://ark.cn-beijing.volces.com/api/v3/chat/completions', '',
       4096, 0.7, 19, 0, 'system', 'system'
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM admin_ai_model WHERE model_identifier = 'doubao-1-5-thinking-vision-pro-250428');

UPDATE admin_ai_scene SET scene_name = '图片识别(多模态)' WHERE scene_code = 'image_recognition';
UPDATE admin_ai_model SET model_name = '通义千问VL(Qwen-VL)' WHERE provider_code = 'qwen' AND model_identifier = 'qwen-vl-plus';
UPDATE admin_ai_model SET model_name = '混元视觉(Hunyuan-Vision)' WHERE provider_code = 'yuanbao' AND model_identifier = 'hunyuan-vision';
UPDATE admin_ai_model SET model_name = '豆包视觉(Doubao-Vision)' WHERE model_identifier = 'doubao-1-5-thinking-vision-pro-250428';