/// The two Nextcloud push registrations every device maintains.
///
/// Nextcloud routes Talk notifications ONLY to registrations whose session
/// user agent matched `IRequest::USER_AGENT_TALK_*` (apptype `talk`) as soon
/// as the user has at least one such device — e.g. the official Talk app.
/// A single `unknown` registration therefore stops receiving Talk pushes the
/// moment the official app is installed. The fix is one registration per
/// route, sharing the same device keypair.
enum PushRegistrationType {
  /// Default registration (apptype `unknown`): files, calendar, everything
  /// except Talk.
  general('general'),

  /// Talk registration (apptype `talk`): Talk messages and calls, ranking
  /// equally beside the official Talk app.
  talk('talk');

  /// Value sent to MarianumConnect as `registrationType`.
  final String wireName;

  const PushRegistrationType(this.wireName);
}

/// Pseudo push token whose sha512 is registered with Nextcloud. The two
/// registrations MUST carry different pushTokenHashes: on registration NC's
/// `deletePushTokenByHash()` removes older subscriptions of the same user
/// with an identical hash — identical hashes would let each registration
/// delete its sibling. The backend derives the same variants from the real
/// FCM token (`registrationType` field), so the proxy hash comparison still
/// matches. Nextcloud never sees the plain token either way.
String pushTokenVariant(String fcmToken, PushRegistrationType type) =>
    switch (type) {
      PushRegistrationType.general => fcmToken,
      PushRegistrationType.talk => '$fcmToken#talk',
    };
