package llc.arma.ble.app.ui.mapper

import llc.arma.ble.app.ui.model.BleView
import llc.arma.ble.domain.model.Ble
import javax.inject.Inject

class BleViewMapper @Inject constructor(
    private val txMapper: TxViewMapper
) : Mapper<BleView, Ble> {

    override fun map(input: BleView): Ble {
        return when(input){
            is BleView.Beacon -> {
                Ble.Beacon(
                    info = input.info,
                    state = Ble.BleState(
                        tx = txMapper.map(input.state.tx)
                    )
                )
            }
            is BleView.Thermometer -> {
                Ble.Thermometer(
                    info = input.info,
                    state = Ble.BleState(
                        tx = txMapper.map(input.state.tx)
                    ),
                    thermometerState = Ble.Thermometer.ThermometerState(
                        temperature = input.thermometerState.temperature.value,
                        historyInterval = input.thermometerState.historyInterval,
                        saveHistory = input.thermometerState.saveHistory
                    )
                )
            }

            is BleView.Accelerometer -> {
                Ble.Accelerometer(
                    info = input.info,
                    state = Ble.BleState(
                        tx = txMapper.map(input.state.tx)
                    ),
                    accelerometerState = Ble.Accelerometer.AccelerometerState(
                        saveHistorySettings = input.accelerometerState.saveHistory,
                        historyInterval = input.accelerometerState.historyInterval,
                    )
                )
            }

            is BleView.Host -> {
                Ble.Host(
                    info = input.info,
                    state = Ble.BleState(
                        tx = txMapper.map(input.state.tx)
                    ),
                    hostState = Ble.Host.HostState(
                        historyInterval = input.hostState.historyInterval,
                        readInterval = input.hostState.readInterval
                    )
                )
            }
        }
    }

}