package com.app.wave.keyboard.database

import com.app.wave.keyboard.bean.DetailsBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object DBManager {


    suspend fun addLike(data: DetailsBean) {
        withContext(Dispatchers.IO) {
            BaseDB.baseDB.ThemesDao().insertData(data)
        }

    }
    suspend fun removeLike(data: DetailsBean) {
        withContext(Dispatchers.IO) {
            val queryIsLike = BaseDB.baseDB.ThemesDao().queryIsLike(data.titleName)
            if (queryIsLike != null) {
                BaseDB.baseDB.ThemesDao().delete(queryIsLike)
            }
        }

    }
    suspend fun getIsLike(name: String, action: (isLike: Boolean) -> Unit) {
        withContext(Dispatchers.IO) {
            val query = BaseDB.baseDB.ThemesDao().queryIsLike(name)
            withContext(Dispatchers.Main) {
                action.invoke(query != null)
            }
        }

    }
}