import type { PayLinkSendResult } from '../../../services/InvoicePayLinkService.tsx'; // What billing staff are told after sending or ending an emailed pay link. The link itself is never shown. const REFUSAL: Record = { no_payer_address: 'No pay link was sent: there is no email address to send it to. An adult patient needs a sign-in email; a minor needs a related person allowed to pay, with an email.', no_portal_address: 'No pay link was sent: this practice has no patient portal address for the link to open.', no_payment_gateway: 'No pay link was sent: this practice does not take payments online.', invoice_not_payable: 'No pay link was sent: this invoice has nothing left to pay.', email_unavailable: 'The email could not be sent, so no pay link was made. Try again.', link_changed: 'Another pay link for this invoice was sent at the same moment. Nothing more was sent.', }; const RECIPIENT: Record<'patient' | 'payer', string> = { patient: 'the patient', payer: 'each person allowed to pay for this patient', }; export const payLinkSentMessage = (result: PayLinkSendResult): { ok: boolean; text: string } => { if (!result.ok) { return { ok: false, text: REFUSAL[result.reason] ?? 'No pay link was sent. Try again in a moment.' }; } const to = [...new Set(result.sentTo)].map((kind) => RECIPIENT[kind]).join(' and '); return { ok: true, text: `A pay link was emailed to ${to}. It works for 7 days, and replaces any link sent before.` }; }; export const PAY_LINK_ENDED = 'Every pay link sent for this invoice has stopped working.'; export const PAY_LINK_END_FAILED = 'The pay links could not be ended. Try again.';