import 'dart:io';
import 'dart:ui';

import 'package:permission_handler/permission_handler.dart';

import 'AndroidPermissionHandler.dart';
import 'IosPermissionHandler.dart';

class PermissionService {
  static Future<bool> requestPermissions() async {
    var isRequestPermissions = false;
    if (Platform.isIOS) {
      // 调用iOS权限处理逻辑
      isRequestPermissions = await IosPermissionHandler().requestCameraToMicrophonePermissions();
    } else if (Platform.isAndroid) {
      // 调用Android权限处理逻辑
      isRequestPermissions = await AndroidPermissionHandler().requestCameraToMicrophonePermissions();
    }
    return isRequestPermissions;
  }

  static Future<bool> requestStoragePermissions() async {
    var isRequestPermissions = false;
    if (Platform.isIOS) {
      // 调用iOS权限处理逻辑
      isRequestPermissions = await IosPermissionHandler().requestStoragePermission();
    } else if (Platform.isAndroid) {
      // 调用Android权限处理逻辑
      isRequestPermissions = await AndroidPermissionHandler().requestStoragePermission();
    }
    return isRequestPermissions;
  }

  /// 检测是否有权限
  static Future<bool> checkPermission({required List<Permission> permissionList}) async {
    var isRequestPermissions = true;
    ///遍历当前权限申请列表
    for (Permission permission in permissionList) {
      PermissionStatus status = await permission.status;
      ///如果有不允许状态
      if (!status.isGranted) {
        isRequestPermissions = false;
      }
    }
    return isRequestPermissions;
  }
}