import { describe, it, expect } from 'vitest';
import { MODEL_MENU, findPrice } from '@/lib/ai/pricing';

/**
 * The Settings → AI integration model dropdown is sourced from
 * MODEL_MENU. These tests guard the invariants:
 *
 *  - Every menu model id is something findPrice() recognizes (so the
 *    cost estimator won't show "—" for any model the user picks from
 *    the dropdown).
 *  - At least one "recommended" entry per major provider — without it
 *    the UI has nothing to highlight.
 *  - Ollama + openai-compatible menus are intentionally empty (those
 *    providers are gateway-/host-specific).
 *  - At least one Gemini 3.x entry (regression-guard against the
 *    user's "I tried gemini-3.0-pro and got 404" report).
 */

describe('MODEL_MENU', () => {
  it('every menu model id matches a price entry', () => {
    for (const [provider, models] of Object.entries(MODEL_MENU)) {
      for (const m of models) {
        const price = findPrice(m.id);
        expect(
          price,
          `${provider}/${m.id} has no price entry — add it to PRICES in pricing.ts`,
        ).not.toBeNull();
      }
    }
  });

  it('major providers have at least one recommended model', () => {
    for (const provider of ['claude', 'openai', 'gemini'] as const) {
      const recs = MODEL_MENU[provider]?.filter((m) => m.recommended) ?? [];
      expect(
        recs.length,
        `${provider} has no recommended model — UI has nothing to star`,
      ).toBeGreaterThan(0);
    }
  });

  it('ollama + openai-compatible menus are empty (model is host-specific)', () => {
    expect(MODEL_MENU.ollama).toEqual([]);
    expect(MODEL_MENU['openai-compatible']).toEqual([]);
  });

  it('Gemini menu includes a 3.x model (regression: gemini-3.0-pro 404)', () => {
    const ids = MODEL_MENU.gemini.map((m) => m.id);
    const has3x = ids.some((id) => /gemini-3/i.test(id));
    expect(has3x, `gemini menu lacks any 3.x model: ${ids.join(', ')}`).toBe(
      true,
    );
  });

  it('Claude menu includes a Sonnet 4.6 or newer (1M context)', () => {
    const ids = MODEL_MENU.claude.map((m) => m.id);
    const hasModern = ids.some((id) =>
      /claude-(opus-4-7|sonnet-4-6|opus-4-6)/i.test(id),
    );
    expect(
      hasModern,
      `claude menu missing 4.6+ tier: ${ids.join(', ')}`,
    ).toBe(true);
  });
});
