import Foundation

enum DeviceWakeCause: UInt8 {
    
    /// In case of deep sleep, reset was not caused by exit from deep sleep
    case WAKEUP_UNDEFINED = 0
    
    /// Not a wakeup cause, used to disable all wakeup sources with esp_sleep_disable_wakeup_source
    case WAKEUP_ALL = 1
    
    /// Wakeup caused by external signal using RTC_IO
    case WAKEUP_EXT0 = 2
    
    /// Wakeup caused by external signal using RTC_CNTL
    case WAKEUP_EXT1 = 3
    
    /// Wakeup caused by timer
    case WAKEUP_TIMER = 4
    
    /// Wakeup caused by touchpad
    case WAKEUP_TOUCHPAD = 5
    
    /// Wakeup caused by ULP program
    case WAKEUP_ULP = 6
    
    /// Wakeup caused by GPIO (light sleep only on ESP32, S2 and S3)
    case WAKEUP_GPIO = 7
    
    /// Wakeup caused by UART (light sleep only)
    case WAKEUP_UART = 8
    
    /// Wakeup caused by WIFI (light sleep only)
    case WAKEUP_WIFI = 9
    
    /// Wakeup caused by COCPU int
    case WAKEUP_COCPU = 10
    
    /// Wakeup caused by COCPU crash
    case WAKEUP_COCPU_TRAP_TRIG = 11
    
    /// Wakeup caused by BT (light sleep only)
    case WAKEUP_BT = 12
}

extension DeviceWakeCause {
    
    var text: String {
        switch self {
        case .WAKEUP_UNDEFINED:
            return "Power On"
        case .WAKEUP_ALL:
            return ""
        case .WAKEUP_EXT0:
            return "Button"
        case .WAKEUP_EXT1:
            return "EXT1"
        case .WAKEUP_TIMER:
            return "Timer"
        case .WAKEUP_TOUCHPAD:
            return "Touch"
        case .WAKEUP_ULP:
            return "ELP"
        case .WAKEUP_GPIO:
            return "GPIO"
        case .WAKEUP_UART:
            return "UART"
        case .WAKEUP_WIFI:
            return "WiFi"
        case .WAKEUP_COCPU:
            return "CoCPU Interupt"
        case .WAKEUP_COCPU_TRAP_TRIG:
            return "CoCPU Crash"
        case .WAKEUP_BT:
            return "Bluetooth"
        }
    }
}

extension DeviceWakeCause: Codable {
    
}
