/**
 * PrescriptionManager: Handles digital prescription generation.
 */

class PrescriptionManager {
    constructor() {
        this.prescriptions = [];
    }

    generate(patientId, doctorId, medicines, diagnosis, labTests = []) {
        const id = `RX-${Date.now()}`;
        const prescription = {
            id,
            patientId,
            doctorId,
            date: new Date().toISOString(),
            diagnosis,
            medicines, // Array of { name, dosage, frequency, duration, qty }
            labTests   // Array of { testName, instructions }
        };
        
        this.prescriptions.push(prescription);
        
        return {
            success: true,
            prescriptionId: id,
            data: prescription,
            whatsappMessage: `💊 *Digital Prescription from Dr. Sharma*\n\n*Diagnosis:* ${diagnosis}\n\n*Medicines:*\n${medicines.map(m => `- ${m.name}: ${m.dosage} (${m.frequency}) for ${m.duration}`).join('\n')}\n\n` +
                             (labTests.length > 0 ? `🔬 *Lab Tests Recommended:*\n${labTests.map(t => `- ${t.testName}`).join('\n')}\n\n` : "") +
                             `_You can show this message at our pharmacy for a 10% discount._`
        };
    }
}

module.exports = new PrescriptionManager();
