package com.rainbow.app.keyboard.mydb

import com.rainbow.app.keyboard.javabean.DetailsjavaBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object DatabManager {


    suspend fun addLike(data: DetailsjavaBean) {
        withContext(Dispatchers.IO) {
            DatabBase.databBase.ThemesDao().insertData(data)
        }

    }
    suspend fun removeLike(data: DetailsjavaBean) {
        withContext(Dispatchers.IO) {
            val queryIsLike = DatabBase.databBase.ThemesDao().queryIsLike(data.titleName)
            if (queryIsLike != null) {
                DatabBase.databBase.ThemesDao().delete(queryIsLike)
            }
        }

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

    }
}