package llc.arma.ble.domain.model

import llc.arma.ble.domain.usecase.AccelScale
import llc.arma.ble.domain.usecase.AccelViewMode

sealed class Ble(
    var info: BleInfo,
    var state: BleState,
) {

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

        sealed class HistorySettings {

            data class Enabled(
                val scale: AccelScale,
                val mode: AccelViewMode,
                val detailed: Boolean
            ) : HistorySettings()

            data object Disabled : HistorySettings()

        }

        data class WriteRequest(
            val tx: BleState.TX?,
            val saveHistorySettings: HistorySettings?,
            val historyInterval: Long?
        )

        sealed class HistoryPoint {

            class Vibration (
                val date: Long,
                val value: Float
            ) : HistoryPoint()

            class Rotation (
                val date: Long,
                val value: Long
            ) : HistoryPoint()

            class Acceleration (
                val date: Long,
                val x: Float,
                val y: Float,
                val z: Float
            ) : HistoryPoint()

            class Angle (
                val date: Long,
                val x: Float,
                val y: Float,
                val z: Float
            ) : HistoryPoint()

        }

        sealed class RealtimePoint {

            data class Rotation(
                val angle: Float,
                val tmp: Float,
                val turnovers: Int,
            ) : RealtimePoint()

            data class Common(
                val x: Float,
                val y: Float,
                val z: Float,
            ) : RealtimePoint()

            data class Angle(
                val x: Float,
                val y: Float,
                val z: Float,
            ) : RealtimePoint()

            data class Vibration(
                val value: Float
            ) : RealtimePoint()

        }

        class SpectrePoint (
            val frequency: Long,
            val value: Float
        )

        data class AccelerometerState(
            val saveHistorySettings: HistorySettings,
            val historyInterval: Long
        )

    }

    class Beacon(
        info: BleInfo,
        state: BleState,
    ) : Ble(info, state){

        data class WriteRequest(
            val tx: BleState.TX?
        )

    }

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

        class HistoryPoint(
            val date: Long,
            val hit: Boolean,
            val value: List<String>
        )

        data class HostState(
            val historyInterval: Long,
            val readInterval: Long
        )

        data class WriteRequest(
            val tx: BleState.TX?,
            val interval: Long?,
            val readInterval: Long?,
        )

    }

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

        class HistoryPoint(
            val date: Long,
            val value: Float
        )

        data class ThermometerState(
            val temperature: Float,
            val saveHistory: Boolean,
            val historyInterval: Long
        )

        data class WriteRequest(
            val tx: BleState.TX?,
            val saveHistory: Boolean?,
            val historyInterval: Long?
        )

    }

    data class BleState(
        val tx: TX
    ){

        enum class TX {
            MINUS_40, MINUS_20, MINUS_16, MINUS_12, MINUS_8, MINUS_4, ZERO, PLUS_3, PLUS_4;

            companion object
        }

    }

}