import { describe, expect, it } from 'vitest';
import { applyBrandVoice, buildBrandVoiceSystemPrompt, getActiveBrandVoice, normalizeBrandVoice, BRAND_VOICE_LIMITS, } from '../../ai/brand-voice.js';
function profile(over = {}) {
    return { enabled: true, name: 'Acme', tone: 'confident, warm', ...over };
}
function config(brandVoice) {
    return {
        providers: [],
        settings: {
            features: [],
            budget: { alertAtPercentages: [], disableWhenExceeded: false },
            logsRetentionDays: 30,
            brandVoice,
        },
    };
}
describe('buildBrandVoiceSystemPrompt', () => {
    it('returns null when disabled', () => {
        expect(buildBrandVoiceSystemPrompt(profile({ enabled: false }))).toBeNull();
    });
    it('returns null when there is no tone or guidelines', () => {
        expect(buildBrandVoiceSystemPrompt(profile({ tone: '', guidelines: '' }))).toBeNull();
    });
    it('includes brand, tone, audience, guidelines, and a fenced sample', () => {
        const out = buildBrandVoiceSystemPrompt(profile({
            audience: 'developers',
            guidelines: 'No jargon. Use active voice.',
            sampleText: 'Ship faster, sleep better.',
        }));
        expect(out).toContain('Brand: Acme');
        expect(out).toContain('Tone: confident, warm');
        expect(out).toContain('Audience: developers');
        expect(out).toContain('No jargon');
        expect(out).toContain('<<<BRAND_SAMPLE');
        expect(out).toContain('Ship faster, sleep better.');
    });
});
describe('applyBrandVoice', () => {
    it('prepends the voice before the task system prompt', () => {
        const out = applyBrandVoice('Return only JSON.', profile());
        expect(out).toMatch(/^Write in the following brand voice:/);
        expect(out).toContain('Return only JSON.');
        // Voice comes first; task instruction last so it can override format.
        expect(out.indexOf('brand voice')).toBeLessThan(out.indexOf('Return only JSON.'));
    });
    it('returns the original system prompt untouched when no voice applies', () => {
        expect(applyBrandVoice('sys', profile({ enabled: false }))).toBe('sys');
        expect(applyBrandVoice(undefined, undefined)).toBeUndefined();
    });
});
describe('getActiveBrandVoice', () => {
    it('returns null when disabled or empty, the profile when usable', () => {
        expect(getActiveBrandVoice(config(undefined))).toBeNull();
        expect(getActiveBrandVoice(config(profile({ enabled: false })))).toBeNull();
        expect(getActiveBrandVoice(config(profile({ tone: '', guidelines: '' })))).toBeNull();
        expect(getActiveBrandVoice(config(profile()))?.name).toBe('Acme');
    });
});
describe('normalizeBrandVoice', () => {
    it('clamps long fields and coerces enabled', () => {
        const long = 'x'.repeat(5000);
        const out = normalizeBrandVoice({
            enabled: 1,
            name: long,
            tone: long,
            guidelines: long,
            sampleText: long,
        });
        expect(out.enabled).toBe(true);
        expect(out.name.length).toBe(BRAND_VOICE_LIMITS.name);
        expect(out.tone.length).toBe(BRAND_VOICE_LIMITS.tone);
        expect(out.guidelines.length).toBe(BRAND_VOICE_LIMITS.guidelines);
        expect(out.sampleText.length).toBe(BRAND_VOICE_LIMITS.sampleText);
    });
    it('drops empty optional fields to undefined', () => {
        const out = normalizeBrandVoice({ enabled: false, name: 'A', tone: 'b', audience: '   ' });
        expect(out.audience).toBeUndefined();
        expect(out.guidelines).toBeUndefined();
        expect(out.sampleText).toBeUndefined();
    });
});
//# sourceMappingURL=brand-voice.test.js.map