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

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
import llc.arma.ble.domain.model.BleInfo

class HostContract {

    sealed class Event : ViewEvent {

        data object OnWriteBle : Event()

        data object OnHideWriteBlePreview : Event()

        data object OnShowWriteBlePreview : Event()

        data object OnPowerEdit : Event()

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

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

        data class OnTxChanged(val tx: Int) : Event()

        data object OnShowIntervalEdit : Event()

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

        data object OnShowReadIntervalEdit : Event()

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

        data object OnNavigateUpClicked : Event()

        data object OnChangePassword : Event()

        data object OnShowHostHistory : Event()

        data object OnShowHostBleTable : Event()

    }

    sealed class State : ViewState {

        data object Loading : State()

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

            sealed class WriteState {

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

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

                data object Success : WriteState()

                data object Failure : WriteState()

            }

        }

    }

    sealed class Effect : ViewSideEffect {

        data object ShowPowerPicker : Effect()

        data object HidePowerPicker : Effect()

        data object HideWriteBlePreview : Effect()

        data object ShowWriteBlePreview : Effect()

        data object HideIntervalPicker : Effect()

        data object ShowIntervalPicker : Effect()

        data object HideReadIntervalPicker : Effect()

        data object ShowReadIntervalPicker : Effect()

        sealed class Navigation : Effect() {

            data object NavigateToChangePassword : Navigation()

            data object NavigateUp : Navigation()

            data class NavigateToHostHistory(
                val ble: BleInfo,
            ) : Navigation()

            data class NavigateToBleTable(
                val serial: String,
            ) : Navigation()

        }

    }

}