import { describe, expect, it } from 'vitest';
import { deriveBrandVoiceFields, parseBrandVoiceDocument, serializeBrandVoiceDocument, splitBrandVoiceDocument, } from '../../ai/brand-voice-document.js';
import { prepareBrandVoiceForSave } from '../../ai/brand-voice-save.js';
const SAMPLE_PROFILE = serializeBrandVoiceDocument({
    fields: {
        name: 'Acme Marketing',
        tone: 'A knowledgeable colleague who respects your time.',
        audience: 'Marketing managers at mid-market B2B firms.',
        guidelines: "Do:\n- Lead with the benefit\n\nDon't:\n- No hype words",
        sampleText: 'We help teams ship with clarity.',
    },
    meta: { version: 2, status: 'draft', generatedFrom: ['collection:posts'] },
});
describe('splitBrandVoiceDocument', () => {
    it('splits YAML frontmatter from markdown body', () => {
        const split = splitBrandVoiceDocument(SAMPLE_PROFILE);
        expect(split?.frontmatter).toContain('profile:');
        expect(split?.body).toContain('# Brand Voice — Human Guidance');
    });
});
describe('parseBrandVoiceDocument', () => {
    it('round-trips a serialized profile', () => {
        const parsed = parseBrandVoiceDocument(SAMPLE_PROFILE);
        expect(parsed.ok).toBe(true);
        if (!parsed.ok)
            return;
        expect(parsed.value.fields.name).toBe('Acme Marketing');
        expect(parsed.value.fields.tone).toContain('knowledgeable colleague');
        expect(parsed.value.fields.audience).toContain('Marketing managers');
        expect(parsed.value.meta.version).toBe(2);
        expect(parsed.value.meta.generatedFrom).toContain('collection:posts');
    });
    it('rejects documents without frontmatter', () => {
        const parsed = parseBrandVoiceDocument('# Just markdown');
        expect(parsed.ok).toBe(false);
    });
});
describe('deriveBrandVoiceFields', () => {
    it("extracts Do/Don't sections into guidelines", () => {
        const split = splitBrandVoiceDocument(SAMPLE_PROFILE);
        const fields = deriveBrandVoiceFields(split.body, split.frontmatter);
        expect(fields.guidelines).toContain('Do:');
        expect(fields.guidelines).toContain("Don't:");
    });
});
describe('prepareBrandVoiceForSave', () => {
    it('regenerates the markdown document from quick-edit fields', () => {
        const saved = prepareBrandVoiceForSave({
            enabled: true,
            name: 'Acme',
            tone: 'warm, direct',
            audience: 'teams',
            guidelines: 'Do:\n- Be clear',
            sampleText: 'Sample paragraph.',
            version: 2,
            preferDocument: false,
        });
        expect(saved.document).toContain('brand_name: Acme');
        expect(saved.document).toContain('warm, direct');
        expect(saved.version).toBe(3);
    });
    it('trusts the markdown document when preferDocument is true', () => {
        const saved = prepareBrandVoiceForSave({
            enabled: true,
            name: 'Stale name',
            tone: 'stale tone',
            document: SAMPLE_PROFILE,
            preferDocument: true,
        });
        expect(saved.name).toBe('Acme Marketing');
        expect(saved.document).toBe(SAMPLE_PROFILE.trim());
    });
});
//# sourceMappingURL=brand-voice-document.test.js.map