"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const system_prompt_js_1 = require("./system-prompt.js");
function makeDNA(overrides) {
    return {
        id: 'char-1',
        createdAt: '2025-01-01T00:00:00Z',
        updatedAt: '2025-01-01T00:00:00Z',
        status: 'active',
        identity: { name: 'Aylin', age: 24, nationality: 'Türk', city: 'İstanbul', occupation: 'model', personality_tags: ['eğlenceli', 'dışa dönük'], mbti: 'ENFP', backstory: 'İstanbullu genç bir model' },
        physicalMeasurements: { height_cm: 172, weight_kg: 56, body_type: 'slim', measurements: { bust: 88, waist: 62, hips: 90 } },
        skinMap: { base: '#F5D0A9', shadow: '#D4A574', highlight: '#FFE4C4' },
        faceAnatomy: { eye_shape: 'almond', eye_color: '#8B4513', eyebrow_shape: 'arched', nose_type: 'straight', lip_shape: 'full', cheekbones: 'high', jawline: 'soft', distinctive_marks: [] },
        hairDNA: { style: 'wavy', length: 'long', texture: 'silky', root_color: '#3B2F2F', mid_color: '#5C4033', highlight_color: '#8B6914' },
        bodyBiometrics: { body_type_detail: 'hourglass', posture: 'upright', skin_texture: 'smooth' },
        profileView: { best_angle: 'left-45', signature_pose: 'hand-on-hip' },
        expressionMotion: { default_expression: 'smile', smile_type: 'warm', gaze_style: 'direct' },
        makeupStyle: { philosophy: 'natural', skin_finish: 'dewy', colors: { primary: '#C48793', secondary: '#E8B4B8', accent: '#8B0000' } },
        fashionStyle: { aesthetic: 'casual-chic', main_colors: ['#000000', '#FFFFFF'], signature_pieces: ['jeans', 'crop top'] },
        technicalSettings: { camera_body: 'Canon R5', portrait_lens: '85mm f/1.4', full_body_lens: '35mm f/1.4', film_stock: 'Portra 400' },
        ...overrides,
    };
}
function makeProfile(overrides) {
    return {
        characterId: 'char-1',
        style: 'neseli',
        toneOfVoice: { formality: 'casual', emoji_frequency: 'high', message_length: 'medium', humor_level: 'frequent', flirtation_level: 'moderate' },
        languagePatterns: { common_phrases: ['ya', 'hadi', 'çok tatlısın'], filler_words: ['yani', 'şey', 'hani'], reaction_templates: {} },
        salesBehavior: { min_messages_before_pitch: 10, cooldown_minutes: 30, pitch_style: 'playful' },
        ...overrides,
    };
}
function makeHistory(overrides) {
    return {
        characterId: 'char-1',
        telegramUserId: 12345,
        userName: 'Mehmet',
        userInfo: { name: 'Mehmet', interests: ['futbol', 'müzik'], notes: ['İstanbullu'] },
        messages: [],
        lastActivity: new Date().toISOString(),
        totalMessages: 0,
        totalStarsSpent: 0,
        ...overrides,
    };
}
function recentMessage(role, content, hoursAgo = 1) {
    return {
        id: `msg-${Math.random().toString(36).slice(2, 8)}`,
        role,
        content,
        timestamp: new Date(Date.now() - hoursAgo * 60 * 60 * 1000).toISOString(),
    };
}
(0, vitest_1.describe)('buildIdentitySection', () => {
    (0, vitest_1.it)('should include character name, age, city and occupation', () => {
        const section = (0, system_prompt_js_1.buildIdentitySection)(makeDNA());
        (0, vitest_1.expect)(section).toContain('Aylin');
        (0, vitest_1.expect)(section).toContain('24');
        (0, vitest_1.expect)(section).toContain('İstanbul');
        (0, vitest_1.expect)(section).toContain('model');
    });
    (0, vitest_1.it)('should include nationality and MBTI', () => {
        const section = (0, system_prompt_js_1.buildIdentitySection)(makeDNA());
        (0, vitest_1.expect)(section).toContain('Türk');
        (0, vitest_1.expect)(section).toContain('ENFP');
    });
    (0, vitest_1.it)('should include personality tags', () => {
        const section = (0, system_prompt_js_1.buildIdentitySection)(makeDNA());
        (0, vitest_1.expect)(section).toContain('eğlenceli');
        (0, vitest_1.expect)(section).toContain('dışa dönük');
    });
    (0, vitest_1.it)('should include backstory when present', () => {
        const section = (0, system_prompt_js_1.buildIdentitySection)(makeDNA());
        (0, vitest_1.expect)(section).toContain('İstanbullu genç bir model');
    });
    (0, vitest_1.it)('should omit backstory line when empty', () => {
        const dna = makeDNA({ identity: { ...makeDNA().identity, backstory: '' } });
        const section = (0, system_prompt_js_1.buildIdentitySection)(dna);
        (0, vitest_1.expect)(section).not.toContain('Arka planın');
    });
});
(0, vitest_1.describe)('buildStyleSection', () => {
    (0, vitest_1.it)('should include style description for predefined styles', () => {
        const section = (0, system_prompt_js_1.buildStyleSection)(makeProfile({ style: 'neseli' }));
        (0, vitest_1.expect)(section).toContain('Neşeli');
    });
    (0, vitest_1.it)('should use custom description for custom style', () => {
        const section = (0, system_prompt_js_1.buildStyleSection)(makeProfile({
            style: 'custom',
            customStyleDescription: 'Çok özel bir tarz, romantik ve derin.',
        }));
        (0, vitest_1.expect)(section).toContain('Çok özel bir tarz, romantik ve derin.');
    });
    (0, vitest_1.it)('should include common phrases', () => {
        const section = (0, system_prompt_js_1.buildStyleSection)(makeProfile());
        (0, vitest_1.expect)(section).toContain('ya');
        (0, vitest_1.expect)(section).toContain('hadi');
        (0, vitest_1.expect)(section).toContain('çok tatlısın');
    });
    (0, vitest_1.it)('should include filler words', () => {
        const section = (0, system_prompt_js_1.buildStyleSection)(makeProfile());
        (0, vitest_1.expect)(section).toContain('yani');
        (0, vitest_1.expect)(section).toContain('şey');
    });
    (0, vitest_1.it)('should handle all 8 predefined styles', () => {
        const styles = ['tipik_turk_kizi', 'tripli', 'alingan', 'neseli', 'gizemli', 'soguk', 'ilgili', 'oyuncu'];
        for (const style of styles) {
            const section = (0, system_prompt_js_1.buildStyleSection)(makeProfile({ style }));
            (0, vitest_1.expect)(section.length).toBeGreaterThan(20);
        }
    });
});
(0, vitest_1.describe)('buildHistorySummary', () => {
    (0, vitest_1.it)('should indicate first conversation when no messages', () => {
        const summary = (0, system_prompt_js_1.buildHistorySummary)(makeHistory());
        (0, vitest_1.expect)(summary).toContain('İlk kez');
    });
    (0, vitest_1.it)('should show recent message counts', () => {
        const history = makeHistory({
            messages: [
                recentMessage('user', 'Merhaba!', 1),
                recentMessage('assistant', 'Selam!', 0.5),
                recentMessage('user', 'Nasılsın?', 0.3),
            ],
        });
        const summary = (0, system_prompt_js_1.buildHistorySummary)(history);
        (0, vitest_1.expect)(summary).toContain('3');
        (0, vitest_1.expect)(summary).toContain('kullanıcı: 2');
        (0, vitest_1.expect)(summary).toContain('sen: 1');
    });
    (0, vitest_1.it)('should filter messages outside the time window', () => {
        const history = makeHistory({
            messages: [
                recentMessage('user', 'Eski mesaj', 100),
                recentMessage('user', 'Yeni mesaj', 1),
            ],
        });
        const summary = (0, system_prompt_js_1.buildHistorySummary)(history, 72);
        (0, vitest_1.expect)(summary).toContain('1');
        (0, vitest_1.expect)(summary).not.toContain('Eski mesaj');
    });
    (0, vitest_1.it)('should show last user and assistant messages', () => {
        const history = makeHistory({
            messages: [
                recentMessage('user', 'Bugün ne yapıyorsun?', 2),
                recentMessage('assistant', 'Evdeyim, sen?', 1.5),
            ],
        });
        const summary = (0, system_prompt_js_1.buildHistorySummary)(history);
        (0, vitest_1.expect)(summary).toContain('Bugün ne yapıyorsun?');
        (0, vitest_1.expect)(summary).toContain('Evdeyim, sen?');
    });
    (0, vitest_1.it)('should indicate no recent conversation when all messages are old', () => {
        const history = makeHistory({
            messages: [recentMessage('user', 'Çok eski', 200)],
        });
        const summary = (0, system_prompt_js_1.buildHistorySummary)(history, 72);
        (0, vitest_1.expect)(summary).toContain('son 72 saat');
    });
    (0, vitest_1.it)('should truncate long messages', () => {
        const longMsg = 'A'.repeat(200);
        const history = makeHistory({
            messages: [recentMessage('user', longMsg, 1)],
        });
        const summary = (0, system_prompt_js_1.buildHistorySummary)(history);
        (0, vitest_1.expect)(summary).toContain('...');
    });
    (0, vitest_1.it)('should respect custom hoursBack parameter', () => {
        const history = makeHistory({
            messages: [recentMessage('user', 'Son mesaj', 20)],
        });
        // 24 saat penceresi — mesaj 20 saat önce, dahil olmalı
        const summary24 = (0, system_prompt_js_1.buildHistorySummary)(history, 24);
        (0, vitest_1.expect)(summary24).toContain('Son mesaj');
        // 10 saat penceresi — mesaj 20 saat önce, dahil olmamalı
        const summary10 = (0, system_prompt_js_1.buildHistorySummary)(history, 10);
        (0, vitest_1.expect)(summary10).toContain('son 10 saat');
    });
});
(0, vitest_1.describe)('buildSystemPrompt', () => {
    (0, vitest_1.it)('should include all 5 base sections without history', () => {
        const prompt = (0, system_prompt_js_1.buildSystemPrompt)(makeDNA(), makeProfile());
        // 1. Identity
        (0, vitest_1.expect)(prompt).toContain('Aylin');
        // 2. Style
        (0, vitest_1.expect)(prompt).toContain('Konuşma Tarzı');
        // 3. Tone guide
        (0, vitest_1.expect)(prompt).toContain('Ses Tonu Rehberi');
        // 4. Sales rules
        (0, vitest_1.expect)(prompt).toContain('Satış Yönlendirme');
        // 5. Busy scenarios
        (0, vitest_1.expect)(prompt).toContain('Mesguliyet Senaryolari');
    });
    (0, vitest_1.it)('should include history and user info sections when history is provided', () => {
        const history = makeHistory({
            messages: [recentMessage('user', 'Selam!', 1)],
        });
        const prompt = (0, system_prompt_js_1.buildSystemPrompt)(makeDNA(), makeProfile(), history);
        // 6. History summary
        (0, vitest_1.expect)(prompt).toContain('Konuşma Geçmişi');
        // 7. User info
        (0, vitest_1.expect)(prompt).toContain('Kullanıcı Bilgileri');
        (0, vitest_1.expect)(prompt).toContain('Mehmet');
        (0, vitest_1.expect)(prompt).toContain('futbol');
    });
    (0, vitest_1.it)('should not include history sections when history is undefined', () => {
        const prompt = (0, system_prompt_js_1.buildSystemPrompt)(makeDNA(), makeProfile());
        (0, vitest_1.expect)(prompt).not.toContain('Kullanıcı Bilgileri');
    });
    (0, vitest_1.it)('should include sales behavior config values', () => {
        const prompt = (0, system_prompt_js_1.buildSystemPrompt)(makeDNA(), makeProfile());
        (0, vitest_1.expect)(prompt).toContain('10');
        (0, vitest_1.expect)(prompt).toContain('30 dakika');
    });
    (0, vitest_1.it)('should include busy scenario examples', () => {
        const prompt = (0, system_prompt_js_1.buildSystemPrompt)(makeDNA(), makeProfile());
        (0, vitest_1.expect)(prompt).toContain('spordayim');
        (0, vitest_1.expect)(prompt).toContain('dustayim');
    });
    (0, vitest_1.it)('should handle user with no known info', () => {
        const history = makeHistory({
            userName: undefined,
            userInfo: { name: undefined, interests: [], notes: [] },
            messages: [recentMessage('user', 'Hey', 1)],
        });
        const prompt = (0, system_prompt_js_1.buildSystemPrompt)(makeDNA(), makeProfile(), history);
        (0, vitest_1.expect)(prompt).toContain('henüz bilgi yok');
    });
    (0, vitest_1.it)('should produce a non-empty string for minimal inputs', () => {
        const prompt = (0, system_prompt_js_1.buildSystemPrompt)(makeDNA(), makeProfile());
        (0, vitest_1.expect)(prompt.length).toBeGreaterThan(100);
    });
});
//# sourceMappingURL=system-prompt.test.js.map