import type { SubscriptionDunning } from './BillingContext.tsx'; /** * The all-staff or stopped warning, read from the notice-only route by a staff member the full bill is closed to. * Anything else stays unknown: this route never carries the administrator's first-failure stage. */ export function dunningFromStaffNotice(notice: unknown): SubscriptionDunning | undefined { if (!notice || typeof notice !== 'object') return undefined; const { stage, daysRemaining } = notice as { stage?: unknown; daysRemaining?: unknown }; if (stage === 'none') return { stage: 'none', notifyAdmin: false, notifyAllStaff: false }; if (stage !== 'all-staff' && stage !== 'stopped') return undefined; const days = typeof daysRemaining === 'number' && Number.isInteger(daysRemaining) && daysRemaining >= 0 ? daysRemaining : undefined; return { stage, notifyAdmin: true, notifyAllStaff: true, daysRemaining: days }; }