"use strict";
/**
 * Mock AI Service
 *
 * Mock implementation of the AI service for testing purposes
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.mockAiService = void 0;
const globals_1 = require("@jest/globals");
/**
 * Mock response for chat requests
 */
const MOCK_CHAT_RESPONSE = {
    id: 'mock-response-id',
    model: 'mock-model',
    created: Date.now(),
    choices: [
        {
            index: 0,
            message: {
                role: 'assistant',
                content: 'This is a mock response from the AI service for testing purposes.'
            },
            finish_reason: 'stop'
        }
    ],
    usage: {
        prompt_tokens: 10,
        completion_tokens: 20,
        total_tokens: 30
    }
};
/**
 * Mock analysis result
 */
const MOCK_DOCUMENT_ANALYSIS = {
    summary: 'This is a mock summary of the analyzed document.',
    keyPoints: [
        'This is the first key point from the mock analysis.',
        'This is the second key point from the mock analysis.',
        'This is the third key point from the mock analysis.'
    ],
    sentiment: 'positive',
    categories: {
        'Technology': 0.8,
        'Business': 0.5,
        'Finance': 0.3
    }
};
/**
 * Mock error for testing error handling
 */
const MOCK_ERROR = {
    code: 'mock_error',
    message: 'This is a mock error from the AI service.',
    details: { cause: 'testing' }
};
/**
 * Mock AI service implementation
 */
exports.mockAiService = {
    /**
     * Mock chat implementation
     */
    chat: globals_1.jest.fn(async (request, options) => {
        // Simulate async operation
        await new Promise(resolve => setTimeout(resolve, 500));
        // Check for specific error triggers in the request
        if (request.messages.some(m => m.content.includes('trigger error'))) {
            throw MOCK_ERROR;
        }
        // If streaming is enabled, call the stream callback
        if (request.stream && options?.onStream) {
            // Simulate streaming chunks
            const content = MOCK_CHAT_RESPONSE.choices[0].message.content;
            const words = content.split(' ');
            for (let i = 0; i < words.length; i++) {
                // Check if aborted
                if (options.abortSignal?.aborted) {
                    throw new Error('Operation aborted');
                }
                // Wait a bit between chunks
                await new Promise(resolve => setTimeout(resolve, 100));
                // Send a chunk
                options.onStream({
                    id: MOCK_CHAT_RESPONSE.id,
                    model: MOCK_CHAT_RESPONSE.model,
                    created: MOCK_CHAT_RESPONSE.created,
                    choices: [{
                            index: 0,
                            delta: {
                                role: i === 0 ? 'assistant' : undefined,
                                content: words[i] + ' '
                            },
                            finish_reason: i === words.length - 1 ? 'stop' : undefined
                        }]
                });
            }
        }
        // Return the mock response
        return {
            ...MOCK_CHAT_RESPONSE,
            choices: [{
                    ...MOCK_CHAT_RESPONSE.choices[0],
                    message: {
                        ...MOCK_CHAT_RESPONSE.choices[0].message,
                        // If request has specific content request, customize the response
                        content: request.messages.some(m => m.content.includes('custom response'))
                            ? 'This is a custom response based on your request.'
                            : MOCK_CHAT_RESPONSE.choices[0].message.content
                    }
                }]
        };
    }),
    /**
     * Mock embeddings implementation
     */
    embeddings: globals_1.jest.fn(async (texts, model) => {
        // Simulate async operation
        await new Promise(resolve => setTimeout(resolve, 300));
        // Check for specific error triggers
        if (texts.some(text => text.includes('trigger error'))) {
            throw MOCK_ERROR;
        }
        // Generate mock embeddings (128-dimensional vectors)
        return texts.map(() => Array.from({ length: 128 }, () => Math.random() * 2 - 1));
    }),
    /**
     * Mock RFP content generation
     */
    generateRFPContent: globals_1.jest.fn(async (rfpDocument, requirements) => {
        // Simulate async operation
        await new Promise(resolve => setTimeout(resolve, 700));
        // Check for specific error triggers
        if (rfpDocument.includes('trigger error')) {
            throw MOCK_ERROR;
        }
        // Generate mock RFP content
        return `This is a mock RFP response for "${rfpDocument.slice(0, 30)}..." with ${requirements.length} requirements.`;
    }),
    /**
     * Mock document analysis
     */
    analyzeDocument: globals_1.jest.fn(async (document, options) => {
        // Simulate async operation
        await new Promise(resolve => setTimeout(resolve, 600));
        // Check for specific error triggers
        if (document.includes('trigger error')) {
            throw MOCK_ERROR;
        }
        // Customize mock result based on options
        const result = { ...MOCK_DOCUMENT_ANALYSIS };
        // If detailed is true, add more key points
        if (options?.detailed) {
            result.keyPoints = [
                ...result.keyPoints,
                'This is an additional key point for detailed analysis.',
                'This is another additional key point for detailed analysis.'
            ];
        }
        // If categories are provided, only include those
        if (options?.categories && options.categories.length > 0) {
            const filteredCategories = {
                Technology: 0,
                Business: 0,
                Finance: 0
            };
            options.categories.forEach((category) => {
                filteredCategories[category] = result.categories[category] || Math.random();
            });
            result.categories = filteredCategories;
        }
        return result;
    }),
    /**
     * Mock metrics retrieval
     */
    getMetrics: globals_1.jest.fn(() => ({
        requests: 42,
        latency: {
            avg: 250,
            p95: 500,
            p99: 750
        },
        errors: 2,
        tokenUsage: 12345
    })),
    /**
     * Mock reset
     */
    resetSDK: globals_1.jest.fn(() => Promise.resolve())
};
exports.default = exports.mockAiService;
//# sourceMappingURL=aiService.mock.js.map