const { isValidZAPhone } = require('./whatsapp'); const ALLOWED_NOTIFICATION_PREFERENCES = ['email', 'whatsapp', 'both']; // WhatsApp/Both requires a valid SA phone number — silently falls back to email otherwise, // since a user without a usable phone number can never receive WhatsApp notifications anyway. function resolveNotificationPreference(requested, phoneNumber, fallback) { if (requested === undefined) return fallback; let pref = ALLOWED_NOTIFICATION_PREFERENCES.includes(requested) ? requested : fallback; if ((pref === 'whatsapp' || pref === 'both') && !isValidZAPhone(phoneNumber)) { pref = 'email'; } return pref; } module.exports = { ALLOWED_NOTIFICATION_PREFERENCES, resolveNotificationPreference };