WITH minimax_hailuo_defs(provider_model_name, capabilities) AS (
  VALUES
    (
      'MiniMax-Hailuo-2.3',
      '{
        "video_generate": {
          "output_resolutions": ["720p", "1080p"],
          "duration_range": {"720p": [6, 10], "1080p": [6, 6]},
          "duration_options": {"720p": [6, 10], "1080p": [6]},
          "aspect_ratio_allowed": []
        },
        "image_to_video": {
          "output_resolutions": ["720p", "1080p"],
          "duration_range": {"720p": [6, 10], "1080p": [6, 6]},
          "duration_options": {"720p": [6, 10], "1080p": [6]},
          "input_first_frame": true,
          "input_first_last_frame": false,
          "input_last_frame": false,
          "input_reference_generate_single": false,
          "input_reference_generate_multiple": false,
          "aspect_ratio_allowed": [],
          "support_video_effect_template": false
        },
        "originalTypes": ["video_generate", "image_to_video"]
      }'::jsonb
    ),
    (
      'MiniMax-Hailuo-2.3-Fast',
      '{
        "image_to_video": {
          "output_resolutions": ["720p", "1080p"],
          "duration_range": {"720p": [6, 10], "1080p": [6, 6]},
          "duration_options": {"720p": [6, 10], "1080p": [6]},
          "input_first_frame": true,
          "input_first_last_frame": false,
          "input_last_frame": false,
          "input_reference_generate_single": false,
          "input_reference_generate_multiple": false,
          "aspect_ratio_allowed": [],
          "support_video_effect_template": false
        },
        "originalTypes": ["image_to_video"]
      }'::jsonb
    )
)
UPDATE base_model_catalog model
SET capabilities = defs.capabilities,
    metadata = CASE
      WHEN jsonb_typeof(model.metadata->'rawModel') = 'object' THEN jsonb_set(model.metadata, '{rawModel,capabilities}', defs.capabilities, true)
      ELSE model.metadata
    END,
    default_snapshot = CASE
      WHEN model.default_snapshot IS NULL THEN NULL
      ELSE jsonb_set(
        CASE
          WHEN jsonb_typeof(model.default_snapshot->'metadata'->'rawModel') = 'object' THEN jsonb_set(model.default_snapshot, '{metadata,rawModel,capabilities}', defs.capabilities, true)
          ELSE model.default_snapshot
        END,
        '{capabilities}',
        defs.capabilities,
        true
      )
    END,
    updated_at = now()
FROM minimax_hailuo_defs defs
WHERE model.provider_key = 'minimax'
  AND model.provider_model_name = defs.provider_model_name
  AND COALESCE(model.metadata->>'source', '') = 'server-main.integration-platform';

WITH minimax_hailuo_defs(provider_model_name, capabilities) AS (
  VALUES
    (
      'MiniMax-Hailuo-2.3',
      '{
        "video_generate": {
          "output_resolutions": ["720p", "1080p"],
          "duration_range": {"720p": [6, 10], "1080p": [6, 6]},
          "duration_options": {"720p": [6, 10], "1080p": [6]},
          "aspect_ratio_allowed": []
        },
        "image_to_video": {
          "output_resolutions": ["720p", "1080p"],
          "duration_range": {"720p": [6, 10], "1080p": [6, 6]},
          "duration_options": {"720p": [6, 10], "1080p": [6]},
          "input_first_frame": true,
          "input_first_last_frame": false,
          "input_last_frame": false,
          "input_reference_generate_single": false,
          "input_reference_generate_multiple": false,
          "aspect_ratio_allowed": [],
          "support_video_effect_template": false
        },
        "originalTypes": ["video_generate", "image_to_video"]
      }'::jsonb
    ),
    (
      'MiniMax-Hailuo-2.3-Fast',
      '{
        "image_to_video": {
          "output_resolutions": ["720p", "1080p"],
          "duration_range": {"720p": [6, 10], "1080p": [6, 6]},
          "duration_options": {"720p": [6, 10], "1080p": [6]},
          "input_first_frame": true,
          "input_first_last_frame": false,
          "input_last_frame": false,
          "input_reference_generate_single": false,
          "input_reference_generate_multiple": false,
          "aspect_ratio_allowed": [],
          "support_video_effect_template": false
        },
        "originalTypes": ["image_to_video"]
      }'::jsonb
    )
)
UPDATE platform_models model
SET capabilities = defs.capabilities,
    updated_at = now()
FROM minimax_hailuo_defs defs, integration_platforms platform, base_model_catalog base_model
WHERE platform.provider = 'minimax'
  AND platform.id = model.platform_id
  AND base_model.id = model.base_model_id
  AND COALESCE(model.provider_model_name, model.model_name) = defs.provider_model_name
  AND COALESCE(base_model.metadata->>'source', '') = 'server-main.integration-platform';
