package com.ardraw.ardrawingflow.util;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public final class PermissionUtil {

    private PermissionUtil() {
    }

    public static boolean hasPerms(Activity activity, String[] permissions) {
        if (activity == null || permissions == null) return false;
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }

    public static void reqPerms(Activity activity, String[] permissions, int requestCode) {
        if (activity != null && permissions != null) {
            ActivityCompat.requestPermissions(activity, permissions, requestCode);
        }
    }

    public static boolean gotPerms(int[] grantResults) {
        if (grantResults == null || grantResults.length == 0) return false;
        for (int result : grantResults) {
            if (result != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }

    public static String[] getStorePerms() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
                ? new String[]{Manifest.permission.READ_MEDIA_IMAGES}
                : new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
    }
}

