package llc.arma.ble.app.ui.model

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import llc.arma.ble.domain.model.Ble
import llc.arma.ble.domain.model.BleInfo

sealed class BleView(
    val info: BleInfo
) {

    class Accelerometer(
        info: BleInfo,
        val state: BleState,
        val accelerometerState: AccelerometerState
    ) : BleView(info) {

        class AccelerometerState(
            saveHistorySettings: Ble.Accelerometer.HistorySettings,
            historyInterval: Long,
        ) {
            var saveHistory by mutableStateOf(saveHistorySettings)
            var historyInterval by mutableStateOf(historyInterval)

        }

    }

    class Beacon(
        info: BleInfo,
        val state: BleState
    ) : BleView(info)

    class Thermometer(
        info: BleInfo,
        val state: BleState,
        val thermometerState: ThermometerState
    ) : BleView(info) {

        class ThermometerState(
            temperature: TemperatureState,
            saveHistory: Boolean,
            historyInterval: Long
        ) {

            class TemperatureState(
                val value: Float,
                val loading: Boolean
            )

            var temperature by mutableStateOf(temperature)
            var saveHistory by mutableStateOf(saveHistory)
            var historyInterval by mutableStateOf(historyInterval)

        }

    }

    class Host(
        info: BleInfo,
        val state: BleState,
        val hostState: HostState
    ) : BleView(info) {

        class HostState(
            historyInterval: Long,
            readInterval: Long
        ) {
            var historyInterval by mutableLongStateOf(historyInterval)
            var readInterval by mutableLongStateOf(readInterval)
        }

    }

    class BleState(
        tx: TX
    ){

        var tx by mutableStateOf(tx)

        enum class TX(val value: Int) {
            MINUS_40(-40),
            MINUS_20(-20),
            MINUS_16(-16),
            MINUS_12(-12),
            MINUS_8(-8),
            MINUS_4(-4),
            ZERO(0),
            PLUS_3(3),
            PLUS_4(4);

            val powerPercentage: Int
                get() {
                    return when(this){
                        MINUS_40 -> 1
                        MINUS_20 -> 5
                        MINUS_16 -> 7
                        MINUS_12 -> 10
                        MINUS_8 -> 16
                        MINUS_4 -> 20
                        ZERO -> 40
                        PLUS_3 -> 80
                        PLUS_4 -> 100
                    }
                }

        }



    }

}