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

const platforms = [
  { id: 'platform-a', name: 'OpenAI Official', internalName: '主账号', platformKey: 'openai-main', provider: 'openai', baseUrl: 'https://api.openai.com', status: 'enabled' },
  { id: 'platform-b', name: 'Volces', platformKey: 'volces', provider: 'volces', baseUrl: 'https://ark.example.com', status: 'disabled' },
] as IntegrationPlatform[];

const models = [
  { id: 'model-a', platformId: 'platform-a', modelName: 'gpt-image-2', providerModelName: 'gpt-image-2', modelAlias: 'image-pro', displayName: 'GPT Image 2', modelType: ['image_generate'], enabled: true },
  { id: 'model-b', platformId: 'platform-b', modelName: 'seedance', providerModelName: 'seedance-v2', displayName: 'Seedance', modelType: ['video_generate'], enabled: true },
] as PlatformModel[];

describe('filterAdminPlatforms', () => {
  it('matches a platform through its bound model name and alias', () => {
    expect(filterAdminPlatforms(platforms, models, {
      query: 'image-pro',
      provider: '',
      status: '',
      now: Date.now(),
    }).map((platform) => platform.id)).toEqual(['platform-a']);
  });

  it('combines provider and runtime status filters', () => {
    expect(filterAdminPlatforms(platforms, models, {
      query: '',
      provider: 'volces',
      status: 'disabled',
      now: Date.now(),
    }).map((platform) => platform.id)).toEqual(['platform-b']);
  });
});
