import 'dart:developer';

import 'package:app_settings/app_settings.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import '../base/widget/dialog/request_permission_dialog.dart';

class NotificationPermission {
  FirebaseMessaging messaging = FirebaseMessaging.instance;
  void requestNotificationsPermission(BuildContext context) async {
    NotificationSettings settings = await messaging.requestPermission(
        alert: true,
        announcement: true,
        badge: true,
        carPlay: true,
        criticalAlert: true,
        provisional: true,
        sound: true);
    if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      log("NotificationsPermission: User granted permission");
    } else if (settings.authorizationStatus ==
        AuthorizationStatus.provisional) {
      log("NotificationsPermission: User granted provisional permission");
    } else {
      log("NotificationsPermission: User denied permission");
      // ignore: use_build_context_synchronously
      RequestPermissionDialog.instance.requestPermissionDialogAndroid(context,
          Icons.location_on_outlined, "ABCDE", AppSettingsType.notification);
    }
  }
}
