import { buildGreetingMessage, buildReminderMessage, toWhatsAppNumber, whatsAppUrl, } from "@/lib/messaging/whatsapp"; import { absoluteUrl } from "@/services/notifications/templates/shared"; import { customerAppointmentLink } from "@/services/scheduling/guest-access.service"; /** * The one place a WhatsApp reminder link for a booking is assembled — shared * by the per-appointment button and the daily reminders list so the two can * never word the message differently. Returns null when the customer has no * phone number WhatsApp could use. */ export function reminderWhatsAppUrl(params: { /** The business's own country (ISO alpha-2) — see getBusinessCountry. */ country: string; businessName: string; timezone: string; customer: { firstName: string; phone: string | null; userId: string | null }; appointment?: { id: string; startAt: Date; staffName: string; serviceNames: string }; }): string | null { const { customer, appointment, businessName, timezone } = params; const digits = toWhatsAppNumber(customer.phone, params.country); if (!digits) return null; if (!appointment) { return whatsAppUrl(digits, buildGreetingMessage({ customerFirstName: customer.firstName, businessName })); } return whatsAppUrl( digits, buildReminderMessage({ customerFirstName: customer.firstName, businessName, services: appointment.serviceNames, staffName: appointment.staffName, dateLabel: appointment.startAt.toLocaleDateString("en-GB", { weekday: "short", day: "numeric", month: "short", timeZone: timezone, }), timeLabel: appointment.startAt.toLocaleTimeString("en-GB", { hour: "2-digit", minute: "2-digit", timeZone: timezone, }), manageUrl: absoluteUrl(customerAppointmentLink({ id: appointment.id, customer: { userId: customer.userId } })), }), ); }