/**
 * Support push notification helper: build title/body/url for a templateKey.
 * Shared by support.notif.push handler.
 */
import { he } from '@/lib/i18n/he';
import { en } from '@/lib/i18n/en';

export function buildSupportPushNotif(
  templateKey: string,
  params: Record<string, string>,
  locale: 'he' | 'en',
): { title: string; body: string; url: string } {
  const ticketId = params['ticketId'] ?? '';
  const shortId = ticketId.slice(0, 8).toUpperCase();
  const url = params['ticketUrl'] ?? (ticketId ? `/support/tickets/${ticketId}` : '/support');

  const templates: Record<string, Record<'he' | 'en', { title: string; body: string }>> = {
    'support.ticket_opened': {
      he: { title: 'הפנייה שלך נפתחה', body: `פנייה #${shortId} — נטפל בה בהקדם` },
      en: { title: 'Your ticket is open', body: `Ticket #${shortId} — we'll respond soon` },
    },
    'support.ticket_resolved': {
      he: { title: 'הפנייה שלך נסגרה', body: `פנייה #${shortId} נסגרה` },
      en: { title: 'Your ticket was resolved', body: `Ticket #${shortId} has been resolved` },
    },
    'support.escalated_to_human': {
      he: { title: 'הפנייה הועברה לנציג', body: `פנייה #${shortId} — נציג יטפל בקרוב` },
      en: { title: 'Escalated to agent', body: `Ticket #${shortId} — an agent will assist soon` },
    },
  };

  const dict = locale === 'en' ? en : he;
  const t = templates[templateKey]?.[locale] ?? {
    title: dict.support_notifications.shared.push_fallback_title,
    body: `#${shortId}`,
  };
  return { title: t.title, body: t.body, url };
}
