import { describe, expect, it } from 'vitest';

import {
  createProviderDraft,
  getProviderConfigMetrics,
  isProviderDraftDirty,
} from '../providerDraft';

describe('providerDraft helpers', () => {
  it('相同配置不会被识别为脏数据', () => {
    const provider = {
      apiKey: 'key',
      endpoint: 'https://api.example.com',
      chatPath: '/v1/chat/completions',
      embedPath: '/v1/embeddings',
      rerankPath: '',
    };

    expect(isProviderDraftDirty(provider, createProviderDraft(provider))).toBe(
      false,
    );
  });

  it('修改任一关键字段后会被识别为脏数据', () => {
    const provider = {
      apiKey: 'key',
      endpoint: 'https://api.example.com',
      chatPath: '/v1/chat/completions',
      embedPath: '',
      rerankPath: '',
    };

    expect(
      isProviderDraftDirty(provider, {
        ...createProviderDraft(provider),
        apiKey: 'next-key',
      }),
    ).toBe(true);
  });

  it('会根据预设路径计算配置完成度', () => {
    const metrics = getProviderConfigMetrics(
      {
        apiKey: 'key',
        endpoint: 'https://api.example.com',
        chatPath: '/v1/chat/completions',
        embedPath: '/v1/embeddings',
        rerankPath: '',
      },
      {
        label: '示例',
        value: 'demo',
        description: '',
        icon: '',
        mode: 'hosted',
        options: {
          chatPath: '/v1/chat/completions',
          embedPath: '/v1/embeddings',
        },
      },
    );

    expect(metrics.completed).toBe(4);
    expect(metrics.total).toBe(4);
    expect(metrics.complete).toBe(true);
  });
});
