/// SAF 权限状态
enum SafPermissionState {
  /// 未授权（首次使用）
  unauthorized,

  /// 已授权，Uri 有效
  authorized,

  /// 授权已过期或 Uri 失效
  expired,

  /// 用户拒绝了授权
  denied,
}

/// SAF 授权结果
class SafAuthorizationResult {
  final bool success;
  final String? uriString;
  final SafPermissionState state;
  final String? errorMessage;

  SafAuthorizationResult(
    {
    required this.success,
    this.uriString,
    required this.state,
    this.errorMessage,
  }
  );

  factory SafAuthorizationResult.success(String uri) {
    return SafAuthorizationResult(
      success: true,
      uriString: uri,
      state: SafPermissionState.authorized,
    );
  }

  factory SafAuthorizationResult.denied() {
    return SafAuthorizationResult(
      success: false,
      state: SafPermissionState.denied,
      errorMessage: '用户拒绝了文件夹访问权限',
    );
  }

  factory SafAuthorizationResult.expired() {
    return SafAuthorizationResult(
      success: false,
      state: SafPermissionState.expired,
      errorMessage: '文件夹访问权限已过期，请重新授权',
    );
  }

  factory SafAuthorizationResult.error(String message) {
    return SafAuthorizationResult(
      success: false,
      state: SafPermissionState.unauthorized,
      errorMessage: message,
    );
  }
}
