import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/Request.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:localstorage/localstorage.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:vibration/vibration.dart';
import 'package:geolocator/geolocator.dart' as geo;
// import 'package:open_settings/open_settings.dart';

class PermissionService extends BaseService {
  final LocalStorage storage = new LocalStorage("permission");
  geo.LocationPermission locationPermission;
  AppGlobal appGlobal = new AppGlobal();

  setVibrationPermission(flag) async {
    storage.setItem('isVibration', flag);
  }

  isVibrationEnabled() {
    return (storage.getItem('isVibration') == null) ||
            (storage.getItem('isVibration')) == false
        ? false
        : true;
  }

  vibrate(callback, context) async {
    if (callback == null) return null;
    if (isVibrationEnabled() == true) {
      if (await Vibration.hasVibrator()) {
        Vibration.vibrate(duration: 100);
        callback();
      }
    } else {
      callback();
    }
  }

  setTheme(flag) async {
    storage.setItem('isTheme', flag);
  }

  isThemeEnabled() {
    return storage.getItem('isTheme');
  }

  cameraPermission() async {
    Map<Permission, PermissionStatus> statuses = await [
      Permission.camera,
    ].request();
  }

  isCameraEnabled() async {
    return await Permission.camera.isGranted;
  }

  setCameraLocationPermission(context) async {
    Navigator.pop(context);
    openAppSettings();
  }

  isLocationEnabled() async {
    var permission = await geo.Geolocator.checkPermission();
    if (permission == geo.LocationPermission.denied) {
      return false;
    } else {
      return true;
    }
  }

  openSettings() async {
    openAppSettings();
  }

  openAccessbility() {
   // OpenSettings.openAppSetting();
  }
}
