export type RemotePushSkipReason =
  | 'missing-push-plugin'
  | 'missing-device-plugin'
  | 'remote-push-not-configured'
  | 'remote-push-disabled';

export interface RemotePushRegistrationGateInput {
  hasPushPlugin: boolean;
  hasDevicePlugin: boolean;
  remotePushConfigured: boolean;
  remotePushEnabled?: boolean;
}

/** Whether the client should call `PushNotifications.register()` on this shell. */
export function shouldRegisterForRemotePush(input: RemotePushRegistrationGateInput): boolean {
  return resolveRemotePushSkipReason(input) === null;
}

/** Resolve the first reason remote push registration should be skipped. */
export function resolveRemotePushSkipReason(
  input: RemotePushRegistrationGateInput
): RemotePushSkipReason | null {
  if (!input.hasPushPlugin) {
    return 'missing-push-plugin';
  }

  if (!input.hasDevicePlugin) {
    return 'missing-device-plugin';
  }

  if (input.remotePushEnabled === false) {
    return 'remote-push-disabled';
  }

  if (!input.remotePushConfigured) {
    return 'remote-push-not-configured';
  }

  return null;
}

/** User-facing console message when remote push registration is skipped. */
export function buildRemotePushSkipMessage(reason: RemotePushSkipReason): string {
  switch (reason) {
    case 'missing-push-plugin':
      return '[mobile] remote push registration skipped: PushNotifications plugin is unavailable on this shell.';
    case 'missing-device-plugin':
      return '[mobile] remote push registration skipped: Device plugin is unavailable on this shell.';
    case 'remote-push-disabled':
      return '[mobile] remote push registration skipped: disabled by environment configuration.';
    case 'remote-push-not-configured':
      return '[mobile] remote push registration skipped: Firebase/APNs is not configured. '
        + 'Add google-services.json (Android) and rebuild to enable push.';
  }
}
