package llc.arma.ble.domain.usecase

import llc.arma.ble.domain.Result
import llc.arma.ble.domain.common.BleException
import llc.arma.ble.domain.model.BleName
import llc.arma.ble.domain.repository.BleNameRepository
import llc.arma.ble.domain.repository.BleRepository
import javax.inject.Inject

class AddBleToHostTable @Inject constructor(
    private val bleRepository: BleRepository,
    private val bleNameRepository: BleNameRepository
) {

    suspend operator fun invoke(serial: String, ble: List<BleName>): Result<Int, BleException> {

        bleNameRepository.save(
            ble.map {
                BleName(
                    serial = it.serial,
                    name = it.name
                )
            }
        )

        return bleRepository.addBleToHostTableBySerial(serial, ble.map { it.serial })

    }

}