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

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 BeaconContract {

    sealed class Event : ViewEvent {

        object OnWriteBle : Event()

        object OnHideWriteBlePreview : Event()

        object OnShowWriteBlePreview : Event()

        object OnPowerEdit : Event()

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

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

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

        object OnNavigateUpClicked : Event()

        object OnChangePassword : Event()

    }

    sealed class State : ViewState {

        object Loading : State()

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

            sealed class WriteState {

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

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

                object Success : WriteState()

                object Failure : WriteState()

            }

        }

    }

    sealed class Effect : ViewSideEffect {

        object ShowPowerPicker : Effect()

        object HidePowerPicker : Effect()

        object HideWriteBlePreview : Effect()

        object ShowWriteBlePreview : Effect()

        sealed class Navigation : Effect() {

            object NavigateToChangePassword : Navigation()

            object NavigateUp : Navigation()

        }

    }

}