import { describe, it, expect } from 'vitest';
import { buildPrompt, PROMPT_VERSION } from '@main/ai/prompt.js';

describe('prompt', () => {
  it('PROMPT_VERSION is 4', () => {
    expect(PROMPT_VERSION).toBe(4);
  });

  it('buildPrompt with empty vocab omits vocabulary line entirely', () => {
    const out = buildPrompt('hello', '2026-05-02', [], []);
    expect(out).not.toContain('vocabulary');
    expect(out).not.toContain('Prefer reusing');
  });

  it('buildPrompt with vocab includes Prefer instruction + comma-separated list', () => {
    const out = buildPrompt('hello', '2026-05-02', [], ['design', 'meeting', 'qa']);
    expect(out).toContain('Existing vocabulary tags');
    expect(out).toContain('design, meeting, qa');
    expect(out).toContain('Prefer reusing');
  });

  it('vocab block appears after header and before JSON rules', () => {
    const out = buildPrompt('hello', '2026-05-02', [], ['design']);
    const headerIdx = out.indexOf("Today's date");
    const vocabIdx = out.indexOf('Existing vocabulary');
    const jsonRulesIdx = out.indexOf('Return a JSON object');
    expect(headerIdx).toBeGreaterThan(-1);
    expect(vocabIdx).toBeGreaterThan(headerIdx);
    expect(jsonRulesIdx).toBeGreaterThan(vocabIdx);
  });
});

describe('buildPrompt with notebooks', () => {
  it('notebooks 목록이 prompt 에 포함됨', () => {
    const p = buildPrompt('hi', '2026-05-14', [], [], ['기본', '회사']);
    expect(p).toContain('기본');
    expect(p).toContain('회사');
    expect(p).toContain('notebook_match');
  });

  it('notebooks 빈 배열 시 notebook 섹션 생략', () => {
    const p = buildPrompt('hi', '2026-05-14', [], [], []);
    expect(p).not.toContain('notebook_match');
    expect(p).not.toContain('사용 가능한 노트북');
  });
});
