/**
 * SET 29c — notification authentication + invocation logging.
 *
 * Two notification paths exist and could previously fail with zero trace:
 *  1. SW path: `chrome.notifications.create` (background.js `tier1:notify`) —
 *     used to wrap failures in an empty catch.
 *  2. Page path: `new Notification` (App.tsx) — never logged an outcome at all.
 *
 * These pure formatters turn either path's outcome into one deterministic
 * log line so a blocked/misconfigured OS notification reads as a logged
 * reason instead of silence. Kept side-effect-free (no `document` / global
 * `Notification` access) so they unit test without a DOM environment.
 */

export type PageNotifyResult =
  | { kind: 'fired' }
  | { kind: 'skipped'; reason: string }
  | { kind: 'error'; message: string };

/** `notify(page): perm=<granted|denied|default|unsupported> hidden=<bool> → <fired|skipped(<reason>)|error(<err>)>` */
export function formatPageNotifyLog(perm: string, hidden: boolean, result: PageNotifyResult): string {
  const tail = result.kind === 'fired'
    ? 'fired'
    : result.kind === 'skipped'
    ? `skipped(${result.reason})`
    : `error(${result.message})`;
  return `notify(page): perm=${perm} hidden=${hidden} → ${tail}`;
}

/** `notify(sw): created id=<id>` / `notify(sw): FAILED <err>` — mirrors background.js's own formatting. */
export function formatSwNotifyLog(result: { id?: string | null; error?: string | null }): string {
  if (result.error) return `notify(sw): FAILED ${result.error}`;
  return `notify(sw): created id=${result.id ?? ''}`;
}
