package llc.arma.ble.app.ui.screen.inspection.thermometer

import llc.arma.ble.app.ui.common.ViewEvent
import llc.arma.ble.app.ui.common.ViewSideEffect
import llc.arma.ble.app.ui.common.ViewState
import llc.arma.ble.app.ui.model.BleView
import llc.arma.ble.domain.model.Ble

class ThermometerContract {

    sealed class Event : ViewEvent {

        object OnWriteBle : Event()

        object OnHideWriteBlePreview : Event()

        object OnShowWriteBlePreview : Event()

        object OnShowTemperatureHistory : Event()

        object OnHideTemperatureHistory : Event()

        object OnChangePassword : Event()

        data class OnSaveHistoryChanged(
            val saveHistory: Boolean
        ) : Event()

        object OnPowerEdit : Event()

        data class OnPowerChanged(
            val tx: BleView.BleState.TX
        ) : Event()

        object OnSaveIntervalEdit : Event()

        data class OnSaveIntervalChanged(
            val interval: Long
        ) : Event()

        data class OnBleChanged(
            val ble: Ble.Thermometer
        ) : Event()

        object OnNavigateUpClicked : Event()

    }

    sealed class State : ViewState {

        object Loading : State()

        data class Display(
            val origin: Ble.Thermometer,
            val thermometer: BleView.Thermometer,
            val writeState: WriteState?
        ) : State() {

            sealed class WriteState {

                data class DisplayPreview(
                    val writeRequest: Ble.Thermometer.WriteRequest
                ) : WriteState()

                data class Writing(
                    val writeRequest: Ble.Thermometer.WriteRequest
                ) : WriteState()

                object Success : WriteState()

                object Failure : WriteState()

            }

        }

    }

    sealed class Effect : ViewSideEffect {

        object ShowTemperatureHistory : Effect()

        object HideTemperatureHistory : Effect()

        object ShowIntervalPicker : Effect()

        object HideIntervalPicker : Effect()

        object ShowPowerPicker : Effect()

        object HidePowerPicker : Effect()

        object ShowWriteBle : Effect()

        object HideWriteBle : Effect()

        sealed class Navigation : Effect() {

            object NavigateUp : Navigation()

            object NavigateToChangePassword : Navigation()

        }

    }

}