const BaseAgent = require('./BaseAgent');

class TriageAgent extends BaseAgent {
    constructor() {
        super('TriageAgent');
        this.responseMocks = {
            'chest pain': JSON.stringify({ category: "URGENT", followUp: "Are you also experiencing shortness of breath or arm pain?" }),
            'fever': JSON.stringify({ category: "MODERATE", followUp: "What is your current temperature?" }),
            'default': JSON.stringify({ category: "ROUTINE", followUp: "How long have you been feeling this way?" })
        };
    }

    async execute(config, payload) {
        const { symptoms } = payload;
        
        console.log(`[TriageAgent] Analyzing symptoms: "${symptoms}"`);
        
        const prompt = `
            Analyze these symptoms: "${symptoms}"
            Determine the urgency (URGENT, MODERATE, ROUTINE) and suggest a follow-up question.
            Return a JSON object: { "category": "...", "followUp": "..." }
        `;

        const llmResponse = await this.mockLLMCall(prompt, this.responseMocks);
        
        try {
            const result = JSON.parse(llmResponse);
            console.log(`[TriageAgent] Triage Result: `, result);
            return result;
        } catch (e) {
            console.error('[TriageAgent] Failed to parse LLM response', e);
            return { category: 'ROUTINE', followUp: 'Please describe your symptoms in more detail.' };
        }
    }
}

module.exports = new TriageAgent();
