// Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

export interface RegisterSWOptions {
  path: string
  scope: string
  immediate?: boolean
  onNeedRefresh?: () => void
  onOfflineReady?: () => void
  /**
   * Called only if `onRegisteredSW` is not provided.
   *
   * @deprecated Use `onRegisteredSW` instead.
   * @param registration The service worker registration if available.
   */
  onRegistered?: (registration: ServiceWorkerRegistration | undefined) => void
  /**
   * Called once the service worker is registered (requires version `0.12.8+`).
   *
   * @param swScriptUrl The service worker script url.
   * @param registration The service worker registration if available.
   */
  onRegisteredSW?: (
    swScriptUrl: string,
    registration: ServiceWorkerRegistration | undefined,
  ) => void
  onRegisterError?: (error: unknown) => void
}

// Contract between the backend push payload, the service worker and the app.
export interface PushNotificationPayload {
  title: string
  body: string
  // Route inside the mobile app, e.g. `/tickets/1`.
  path: string
  tag?: string
}

// Asks the service worker to close every push it shows, see the push store.
export interface ClosePushNotificationsMessage {
  type: 'CLOSE_PUSH_NOTIFICATIONS'
}

export interface PushNotificationClickMessage {
  type: 'PUSH_NOTIFICATION_CLICK'
  path: string
}
