WITH source_providers(provider_key, provider_code, provider_type, display_name, icon_path) AS (
  VALUES
    ('easyai', 'easyai', 'easyai', 'EasyAI', ''),
    ('runninghub', 'runninghub', 'runninghub', 'RunningHub', ''),
    ('LiblibAI', 'LiblibAI', 'LiblibAI', 'LiblibAI', ''),
    ('keling', 'keling', 'keling', '可灵AI', 'https://static.51easyai.com/kling-color.webp'),
    ('gemini', 'google-gemini', 'google-gemini', 'Google Gemini', 'https://static.51easyai.com/gemini-color.png'),
    ('openai', 'openai', 'openai', 'OpenAI', ''),
    ('aliyun-bailian-openai', 'aliyun-bailian-openai', 'openai', '阿里云百炼(OpenAI兼容）', ''),
    ('gemini-openai', 'gemini-openai', 'openai', 'Gemini OpenAI兼容', 'https://static.51easyai.com/gemini-color.png'),
    ('volces-openai', 'volces-openai', 'openai', '火山引擎(OpenAI兼容)', 'https://ecmb.bdimg.com/tam-ogel/1801637412_-164881388_88_88.jpg'),
    ('zhipu-openai', 'zhipu-openai', 'openai', '智谱AI', 'https://static.51easyai.com/chatglm-color.webp'),
    ('minimax-openai', 'minimax-openai', 'openai', 'MiniMax（OpenAI兼容）', 'https://static.51easyai.com/minimax-color.png'),
    ('openrouter-openai', 'openrouter-openai', 'openai', 'OpenRouter', ''),
    ('aliyun-bailian', 'aliyun-bailian', 'aliyun-bailian', '阿里云百炼', 'https://static.51easyai.com/bailian-color.webp'),
    ('ollama', 'ollama', 'openai', 'Ollama', ''),
    ('blackforest', 'blackforest', 'blackforest', '黑森林实验室', 'https://easyai-1253343986.cos.ap-shanghai.myqcloud.com/663e19cd4fa9d8078385c7c9/upload/20250611132907371-blackforest.png'),
    ('dify', 'dify', 'dify', 'Dify', ''),
    ('volces', 'volces', 'volces', '火山引擎（豆包）', 'https://ecmb.bdimg.com/tam-ogel/1801637412_-164881388_88_88.jpg'),
    ('jimeng', 'jimeng', 'jimeng', '即梦AI', 'https://static.51easyai.com/jimeng-logo.png'),
    ('silicon-flow-openai', 'silicon-flow-openai', 'openai', '硅基流动', ''),
    ('tripo3d', 'tripo3d', 'tripo3d', 'Tripo3D', 'https://static.51easyai.com/tripo-logo.png'),
    ('tencent-hunyuan-image', 'tencent-hunyuan-image', 'tencent-hunyuan-image', '腾讯混元生图（第三方）', 'https://static.51easyai.com/hunyuan3d-logo.svg'),
    ('tencent-hunyuan-video', 'tencent-hunyuan-video', 'tencent-hunyuan-video', '腾讯混元视频（第三方）', 'https://static.51easyai.com/hunyuan3d-logo.svg'),
    ('tencent-hunyuan', 'tencent-hunyuan', 'tencent-hunyuan', '腾讯混元3D', 'https://static.51easyai.com/hunyuan3d-logo.svg'),
    ('suno', 'suno', 'suno', 'Suno音乐生成', 'https://static.51easyai.com/suno-logo.png'),
    ('minimax', 'minimax', 'minimax', 'MiniMax', 'https://static.51easyai.com/minimax-color.png'),
    ('midjourney', 'midjourney', 'midjourney', 'Midjourney', 'https://static.51easyai.com/midjourney.png'),
    ('tencent-lke', 'tencent-lke', 'tencent-lke', '腾讯云智能体开发平台', ''),
    ('universal', 'universal', 'universal', '自定义平台通用平台（支持自定义方式接入任意平台）', ''),
    ('newapi', 'newapi', 'newapi', 'NewAPI兼容平台', ''),
    ('vidu', 'vidu', 'vidu', 'Vidu视频生成', 'https://static.51easyai.com/vidu-color.webp'),
    ('n8n', 'n8n', 'n8n', 'n8n', ''),
    ('mock-test', 'mock-test', 'mock-test', 'Mock测试平台', '')
)
INSERT INTO model_catalog_providers (
  provider_key, provider_code, provider_type, display_name, icon_path, source,
  capability_schema, default_rate_limit_policy, metadata, status
)
SELECT provider_key,
       provider_code,
       provider_type,
       display_name,
       NULLIF(icon_path, ''),
       'server-main.integration-platform',
       '{}'::jsonb,
       '{}'::jsonb,
       jsonb_build_object(
         'seed', 'server-main-provider-defaults',
         'syncSource', 'server-main.integration-platform',
         'sourceCode', provider_code,
         'sourceSpecType', provider_type
       ),
       'active'
FROM source_providers
ON CONFLICT (provider_key) DO UPDATE
SET provider_code = EXCLUDED.provider_code,
    display_name = EXCLUDED.display_name,
    provider_type = EXCLUDED.provider_type,
    icon_path = EXCLUDED.icon_path,
    source = EXCLUDED.source,
    metadata = model_catalog_providers.metadata || EXCLUDED.metadata,
    status = EXCLUDED.status,
    updated_at = now();
