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

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

class BleListContract {

    sealed class Event : ViewEvent {

        data object OnResetFilter : Event()

        data object OnHideFilter : Event()

        data object OnShowFilter : Event()

        data class OnConnectToBle(
            val bleAddress: String
        ) : Event()

        data class OnRssiRangeChanged(
            val rssi: ClosedFloatingPointRange<Float>
        ) : Event()

        data class OnBatteryRangeChanged(
            val battery: ClosedFloatingPointRange<Float>
        ) : Event()

        data class OnMacFilterChanged(
            val mac: String
        ) : Event()

        data class OnNameFilterChanged(
            val name: String
        ) : Event()

        data class OnTypeChanged(
            val type: BleInfo.Type?
        ) : Event()

        data class OnSortFieldChanged(
            val field: BleFilter.Field
        ) : Event()

        data class OnSortOrderChanged(
            val order: BleFilter.Order
        ) : Event()

    }

    data class State(
        val connectedBleList: List<ConnectedBleInfo>,
        val bleList: List<BleInfo>,
        val bleFilter: BleFilter
    ) : ViewState {

        /*data class Filter(
            val sortField: Field = Field.Name,
            val sortOrder: Order = Order.Asc,
            val name: String = "",
            val mac: String = "",
            val battery: ClosedFloatingPointRange<Float> = (0f)..(100f),
            val rssi: ClosedFloatingPointRange<Float> = (-100f)..(-10f),
            val bleType: BleInfo.Type? = null
        ){

            enum class Field {
                Name, Mac, Distance, Dbm, Battery
            }

            enum class Order {
                Asc, Desc
            }

        }*/

    }

    sealed class Effect : ViewSideEffect {

        object ShowFilter : Effect()

        object HideFilter : Effect()

        sealed class Navigation : Effect() {

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

        }

    }

}