package partisan.weforge.xyz.pulse

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.provider.Settings
import android.app.role.RoleManager

val REQUIRED_PERMISSIONS = arrayOf(
    Manifest.permission.READ_CONTACTS,
    Manifest.permission.CALL_PHONE,
)

fun hasGeneralPermissions(context: Context): Boolean {
    return REQUIRED_PERMISSIONS.all {
        context.checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED
    }
}

fun hasDrawOverlays(context: Context): Boolean {
    return Settings.canDrawOverlays(context)
}

fun hasCallRedirectionRole(context: Context): Boolean {
    val roleManager = context.getSystemService(RoleManager::class.java)
    return roleManager?.isRoleHeld(RoleManager.ROLE_CALL_REDIRECTION) ?: false
}