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 BleMapper @Inject constructor(
    private val txMapper: TxMapper
) : Mapper<Ble, BleView> {

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

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

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

}