import type { PlatformModel } from '@easyai-ai-gateway/contracts';
import { describe, expect, it } from 'vitest';
import { filterModelsForMode } from './PlaygroundPage';

function model(id: string, modelType: string[]) {
  return { id, modelType } as PlatformModel;
}

function modelIds(models: PlatformModel[]) {
  return models.map((item) => item.id);
}

describe('playground model filtering', () => {
  const models = [
    model('image-generation', ['image_generate']),
    model('legacy-image', ['image']),
    model('image-edit', ['image_edit']),
    model('image-to-video', ['video_generate', 'image_to_video']),
    model('text-to-video', ['text_to_video']),
  ];

  it('only shows image generation models when no reference image is present', () => {
    expect(modelIds(filterModelsForMode(models, 'image', false, 'text_to_video'))).toEqual([
      'image-generation',
      'legacy-image',
    ]);
  });

  it('only shows image editing models when a reference image is present', () => {
    expect(modelIds(filterModelsForMode(models, 'image', true, 'text_to_video'))).toEqual([
      'legacy-image',
      'image-edit',
    ]);
  });

  it('does not fall back to image-to-video models when no image model is available', () => {
    const videoOnlyModels = [
      model('kling-3-turbo', ['video_generate', 'image_to_video']),
      model('kling-1-5', ['image_to_video']),
    ];

    expect(filterModelsForMode(videoOnlyModels, 'image', false, 'text_to_video')).toEqual([]);
  });

  it('keeps image-to-video models available for the matching video mode', () => {
    expect(modelIds(filterModelsForMode(models, 'video', false, 'first_last_frame'))).toContain('image-to-video');
  });
});
