/** * QueueManager: Handles the hybrid slot logic for Curio * - 30-min slots * - Max 3 online bookings (Hard Cap) * - 5 Walk-in slots */ const configManager = require('./configManager'); class QueueManager { constructor() { this.slots = {}; // Key: "tenantId:YYYY-MM-DD:HH:mm" } getSlotKey(tenantId, date, time) { const config = configManager.getTenantConfig(tenantId); const duration = config.slotDuration || 30; const [hours, minutes] = time.split(':'); const roundedMins = parseInt(minutes) < duration ? '00' : duration; return `${tenantId}:${date}:${hours}:${roundedMins}`; } getSlotStatus(tenantId, date, time) { const key = this.getSlotKey(tenantId, date, time); if (!this.slots[key]) { const config = configManager.getTenantConfig(tenantId); this.slots[key] = { online: 0, walkin: 0, maxOnline: config.onlineSlotLimit || 3, maxWalkin: config.walkinSlotLimit || 5 }; } return this.slots[key]; } bookOnline(date, time, tenantId = 'default') { const status = this.getSlotStatus(tenantId, date, time); const config = configManager.getTenantConfig(tenantId); if (status.online < status.maxOnline) { status.online++; return { success: true, token: `ON-${status.online}`, slot: this.getSlotKey(tenantId, date, time), status: 'PENDING_PAYMENT', fee: config.consultationFee }; } return { success: false, message: "Slot full for online booking. Try next slot." }; } bookWalkin(date, time, tenantId = 'default') { const status = this.getSlotStatus(tenantId, date, time); const config = configManager.getTenantConfig(tenantId); if (status.walkin < status.maxWalkin) { status.walkin++; return { success: true, token: `WK-${status.walkin}`, status: 'PENDING_PAYMENT', fee: config.consultationFee }; } return { success: false, message: "Clinic is at full capacity for this slot." }; } getDailyUpdates(patientId, tenantId = 'default') { const config = configManager.getTenantConfig(tenantId); return [ `Good morning! Your appointment with ${config.name} is scheduled for today.`, "Queue Update: The clinic is running 10 mins behind schedule. Please plan accordingly.", "Reminder: Don't forget to bring your previous reports." ]; } } module.exports = new QueueManager();