"use strict";
/**
 * BFRFP Service Integration
 * Connects to the completed BFRFP service for AI-powered RFP analysis
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.bfrfpService = void 0;
class BFRFPService {
    constructor(baseUrl = process.env.REACT_APP_BFRFP_URL || 'http://localhost:3003') {
        this.baseUrl = baseUrl;
        this.timeout = 30000; // 30 seconds
    }
    /**
     * Analyze an RFP document using AI
     */
    async analyzeDocument(request) {
        const response = await fetch(`${this.baseUrl}/api/analyze`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(request),
            signal: AbortSignal.timeout(this.timeout),
        });
        if (!response.ok) {
            throw new Error(`BFRFP analysis failed: ${response.statusText}`);
        }
        return response.json();
    }
    /**
     * Generate RFP response content
     */
    async generateResponse(request) {
        const response = await fetch(`${this.baseUrl}/api/generate`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(request),
            signal: AbortSignal.timeout(this.timeout * 2), // Generation takes longer
        });
        if (!response.ok) {
            throw new Error(`BFRFP generation failed: ${response.statusText}`);
        }
        return response.json();
    }
    /**
     * Get analysis status
     */
    async getAnalysisStatus(analysisId) {
        const response = await fetch(`${this.baseUrl}/api/analyze/${analysisId}/status`);
        if (!response.ok) {
            throw new Error(`Failed to get analysis status: ${response.statusText}`);
        }
        return response.json();
    }
    /**
     * Get recent analyses
     */
    async getRecentAnalyses(limit = 10) {
        const response = await fetch(`${this.baseUrl}/api/analyses?limit=${limit}`);
        if (!response.ok) {
            throw new Error(`Failed to get recent analyses: ${response.statusText}`);
        }
        const data = await response.json();
        return data.analyses || [];
    }
    /**
     * Get generation status
     */
    async getGenerationStatus(generationId) {
        const response = await fetch(`${this.baseUrl}/api/generate/${generationId}/status`);
        if (!response.ok) {
            throw new Error(`Failed to get generation status: ${response.statusText}`);
        }
        return response.json();
    }
    /**
     * Cancel an ongoing analysis
     */
    async cancelAnalysis(analysisId) {
        const response = await fetch(`${this.baseUrl}/api/analyze/${analysisId}/cancel`, {
            method: 'POST',
        });
        if (!response.ok) {
            throw new Error(`Failed to cancel analysis: ${response.statusText}`);
        }
    }
    /**
     * Export analysis results
     */
    async exportAnalysis(analysisId, format) {
        const response = await fetch(`${this.baseUrl}/api/analyze/${analysisId}/export?format=${format}`);
        if (!response.ok) {
            throw new Error(`Failed to export analysis: ${response.statusText}`);
        }
        return response.blob();
    }
    /**
     * Health check for BFRFP service
     */
    async healthCheck() {
        try {
            const response = await fetch(`${this.baseUrl}/api/health`, {
                signal: AbortSignal.timeout(5000),
            });
            return response.ok;
        }
        catch {
            return false;
        }
    }
}
// Export singleton instance
exports.bfrfpService = new BFRFPService();
//# sourceMappingURL=bfrfp.js.map