// WhatsApp counterpart of email templates.lib. Same 4 touchpoints, plain
// text bodies (WhatsApp doesn't render HTML — its tiny markdown subset for
// *bold* and _italic_ passes through untouched). Each default kept short
// since WhatsApp messages are read on a phone and verbose copy gets
// scrolled past.

/** Variables exposed to every WhatsApp template. Shared shape so the
 *  in-app editor doesn't have to switch its variable list per type. */
export interface WhatsAppVars {
  visitor_name: string;
  visitor_email: string;
  visitor_mobile: string;
  visitor_id: string;
  visit_date: string;
  visit_time: string;
  visit_notes: string;
  reason_for_visit: string;
  host_name: string;
  host_email: string;
  organization: string;
  // Public link surfaces — kept as full URLs so the user can click them
  // from the WhatsApp message and land directly on the relevant action.
  pass_url: string;
  // QR image URL. Recipient tapping the link sees the QR PNG inline in
  // their browser, then can show it at reception. WhatsApp doesn't render
  // image variables inline in a templated text message, so a URL is the
  // closest practical surface.
  qr_code: string;
  approve_url: string;
  reject_url: string;
}

export const WHATSAPP_KNOWN_KEYS: ReadonlyArray<keyof WhatsAppVars> = [
  'visitor_name', 'visitor_email', 'visitor_mobile', 'visitor_id',
  'visit_date', 'visit_time', 'visit_notes', 'reason_for_visit',
  'host_name', 'host_email', 'organization',
  'pass_url', 'qr_code', 'approve_url', 'reject_url',
];

// Approver-request adds the decision URLs to the variable surface used by
// the editor; the rest of the templates omit them from their hints to
// avoid confusing copy.
export const WHATSAPP_APPROVER_REQUEST_EXTRA_KEYS: ReadonlyArray<keyof WhatsAppVars> = [
  'approve_url', 'reject_url',
];

/** Sample values used to render the in-app preview. Mirrors the email
 *  sample data so a preview side-by-side feels coherent. */
export const WHATSAPP_SAMPLE: WhatsAppVars = {
  visitor_name: 'Priya Sharma',
  visitor_email: 'priya@example.com',
  visitor_mobile: '+919876543210',
  visitor_id: 'X4JTI6MGJE',
  visit_date: 'Mon, May 19, 2026',
  visit_time: '10:00 AM',
  visit_notes: 'Quarterly audit prep — escort to floor 4',
  reason_for_visit: 'Audit',
  host_name: 'Hardip K',
  host_email: 'hardip.k@upsquare.in',
  organization: 'Gate Pass HQ',
  pass_url: 'https://example.com/pass/X4JTI6MGJE',
  // Relative URL so the in-app preview (web origin) resolves it against
  // the dev server, which proxies /api → API and serves a real QR PNG.
  // The actual send pipeline overrides this with an absolute URL built
  // from APP_URL / API_PUBLIC_URL so the recipient gets a clickable link.
  qr_code: '/api/public/qr/X4JTI6MGJE.png',
  approve_url: 'https://example.com/decide/preview-approve',
  reject_url: 'https://example.com/decide/preview-reject',
};

export const DEFAULT_WHATSAPP_INVITE = {
  body:
    `Hi {{visitor_name}}, you're invited to visit *{{organization}}* on {{visit_date}} at {{visit_time}}.\n\n` +
    `*Host:* {{host_name}}\n` +
    `*Reason:* {{reason_for_visit}}\n` +
    `*Pass ID:* {{visitor_id}}\n\n` +
    `*Your QR:* {{qr_code}}\n\n` +
    `Show the QR (or the Pass ID) at reception when you arrive.\n\n` +
    `See you soon!`,
};

export const DEFAULT_WHATSAPP_CHECK_IN = {
  body:
    `Welcome to *{{organization}}*, {{visitor_name}}!\n\n` +
    `You're checked in for your meeting with {{host_name}}.\n` +
    `*Pass ID:* {{visitor_id}}\n\n` +
    `Have a great visit.`,
};

export const DEFAULT_WHATSAPP_REMINDER = {
  body:
    `Reminder: your visit to *{{organization}}* is coming up.\n\n` +
    `*When:* {{visit_date}} at {{visit_time}}\n` +
    `*Host:* {{host_name}}\n` +
    `*Pass ID:* {{visitor_id}}\n` +
    `*Your QR:* {{qr_code}}\n\n` +
    `Show the QR (or the Pass ID) at reception to check in.`,
};

export const DEFAULT_WHATSAPP_APPROVER_REQUEST = {
  body:
    `Hi {{host_name}}, *{{visitor_name}}* has arrived at *{{organization}}* and is awaiting your approval.\n\n` +
    `*Reason:* {{reason_for_visit}}\n` +
    `*Mobile:* {{visitor_mobile}}\n\n` +
    `Approve: {{approve_url}}\n` +
    `Reject: {{reject_url}}`,
};
