package cl.homelogic.platform.common.permissions

import cl.homelogic.platform.common.permissions.PermissionStatus.Denied
import cl.homelogic.platform.common.permissions.PermissionStatus.Granted
import cl.homelogic.platform.common.permissions.PermissionStatus.NotGranted
import dev.icerock.moko.permissions.Permission
import dev.icerock.moko.permissions.PermissionState
import dev.icerock.moko.permissions.bluetooth.BluetoothAdvertisePermission
import dev.icerock.moko.permissions.bluetooth.BluetoothConnectPermission
import dev.icerock.moko.permissions.bluetooth.BluetoothLEPermission
import dev.icerock.moko.permissions.bluetooth.BluetoothScanPermission
import dev.icerock.moko.permissions.camera.CameraPermission
import dev.icerock.moko.permissions.contacts.ContactPermission
import dev.icerock.moko.permissions.gallery.GalleryPermission
import dev.icerock.moko.permissions.location.BackgroundLocationPermission
import dev.icerock.moko.permissions.location.CoarseLocationPermission
import dev.icerock.moko.permissions.location.LocationPermission
import dev.icerock.moko.permissions.microphone.RecordAudioPermission
import dev.icerock.moko.permissions.motion.MotionPermission
import dev.icerock.moko.permissions.notifications.RemoteNotificationPermission
import dev.icerock.moko.permissions.storage.StoragePermission
import dev.icerock.moko.permissions.storage.WriteStoragePermission

enum class PermissionType {
    CAMERA,
    GALLERY,
    STORAGE,
    WRITE_STORAGE,
    LOCATION,
    COARSE_LOCATION,
    BACKGROUND_LOCATION,
    BLUETOOTH_LE,
    REMOTE_NOTIFICATION,
    RECORD_AUDIO,
    BLUETOOTH_SCAN,
    BLUETOOTH_ADVERTISE,
    BLUETOOTH_CONNECT,
    CONTACTS,
    MOTION,
    ;

    companion object {
        fun PermissionType.toMokoPermission() =
            when (this) {
                CAMERA -> CameraPermission
                GALLERY -> GalleryPermission
                STORAGE -> StoragePermission
                WRITE_STORAGE -> WriteStoragePermission
                LOCATION -> LocationPermission
                COARSE_LOCATION -> CoarseLocationPermission
                BACKGROUND_LOCATION -> BackgroundLocationPermission
                BLUETOOTH_LE -> BluetoothLEPermission
                REMOTE_NOTIFICATION -> RemoteNotificationPermission
                RECORD_AUDIO -> RecordAudioPermission
                BLUETOOTH_SCAN -> BluetoothScanPermission
                BLUETOOTH_ADVERTISE -> BluetoothAdvertisePermission
                BLUETOOTH_CONNECT -> BluetoothConnectPermission
                CONTACTS -> ContactPermission
                MOTION -> MotionPermission
            }
    }
}

fun PermissionState.toPermissionStatus() =
    when (this) {
        PermissionState.NotDetermined -> NotGranted
        PermissionState.NotGranted -> NotGranted
        PermissionState.Granted -> Granted
        PermissionState.Denied -> Denied
        PermissionState.DeniedAlways -> Denied
    }

enum class PermissionStatus {
    NotGranted,
    Granted,
    Denied,
}
