package llc.arma.ble.app.ui.screen.connection

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
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.screen.inspection.accelerometer.AccelerometerContract
import llc.arma.ble.app.ui.screen.inspection.beacon.BeaconContract
import llc.arma.ble.app.ui.screen.inspection.host.HostContract
import llc.arma.ble.app.ui.screen.inspection.thermometer.ThermometerContract
import llc.arma.ble.domain.common.BleException
import llc.arma.ble.domain.model.Ble
import llc.arma.ble.domain.model.BleInfo
import llc.arma.ble.domain.usecase.AccelScale
import llc.arma.ble.domain.usecase.AccelViewMode
import llc.arma.ble.domain.usecase.FftAxis
import llc.arma.ble.domain.usecase.FftFrequency
import llc.arma.ble.domain.usecase.FftViewMode

class ConnectionContract {

    sealed class Event : ViewEvent {

        data object RefreshBle : Event()

        data object OnNavigateUp : Event()

        data class OnBeaconNavigationEvent(
            val event: BeaconContract.Effect.Navigation
        ) : Event()

        data class OnHostNavigationEvent(
            val event: HostContract.Effect.Navigation
        ) : Event()

        data class OnThermometerNavigationEvent(
            val event: ThermometerContract.Effect.Navigation
        ) : Event()

        data class OnAccelNavigationEvent(
            val event: AccelerometerContract.Effect.Navigation
        ) : Event()


    }

    sealed class State : ViewState {

        data object Loading : State()

        data class DisplayException(
            val exception: BleException
        ) : State()

        data class Display(
            val ble: Ble
        ) : State()

    }

    sealed class Effect : ViewSideEffect {

        sealed class Navigation : Effect() {

            data object NavigateUp : Navigation()

            data class NavigateToChangePassword(
                val serial: String
            ) : Navigation()

            data class NavigateToRotationsStatistic(
                val serial: String
            ) : Navigation()

        }

        sealed class InnerNavigation : Effect() {

            @Parcelize
            data class NavigateToAccelHistory(
                val ble: BleInfo,
                val accelScale: AccelScale,
                val accelMode: AccelViewMode,
                val fftAxis: FftAxis,
                val fftMode: FftViewMode,
                val frequency: FftFrequency
            ) : InnerNavigation(), Parcelable

            @Parcelize
            data class NavigateToAccelRealtime(
                val ble: BleInfo,
                val accelScale: AccelScale,
                val accelMode: AccelViewMode,
                val fftAxis: FftAxis,
                val fftMode: FftViewMode,
                val frequency: FftFrequency
            ) : InnerNavigation(), Parcelable

            @Parcelize
            data class NavigateToAccelSpectre(
                val ble: BleInfo,
                val accelScale: AccelScale,
                val accelMode: AccelViewMode,
                val fftAxis: FftAxis,
                val fftMode: FftViewMode,
                val frequency: FftFrequency
            ) : InnerNavigation(), Parcelable

            @Parcelize
            data class NavigateToHostHistory(
                val ble: BleInfo
            ) : InnerNavigation(), Parcelable

            @Parcelize
            data class NavigateHostToBleTable(
                val serial: String
            ) : InnerNavigation(), Parcelable

        }

    }

}