package llc.arma.ble.data.repository

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import llc.arma.ble.data.db.BleNameDao
import llc.arma.ble.data.model.BleNameEntity
import llc.arma.ble.domain.model.BleName
import llc.arma.ble.domain.repository.BleNameRepository
import javax.inject.Inject

class BleNameRepositoryImpl @Inject constructor(
    private val bleNameDao: BleNameDao
) : BleNameRepository {

    override suspend fun save(names: List<BleName>) {
        bleNameDao.save(
            names.map {
                BleNameEntity(
                    serial = it.serial,
                    name = it.name
                )
            }
        )
    }

    override fun getNamesFlow(): Flow<List<BleName>> {
        return bleNameDao.getAllFlow().map { list ->
            list.map {
                BleName(
                    serial = it.serial,
                    name = it.name
                )
            }
        }
    }

}