package com.keyborad.theme.trendyborad.database

import com.keyborad.theme.trendyborad.bean.BeanDetails
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object DatabaseManager {


    suspend fun addLike(data: BeanDetails) {
        withContext(Dispatchers.IO) {
            BaseDataBase.baseDataBase.ThemesDao().insertData(data)
        }

    }
    suspend fun removeLike(data: BeanDetails) {
        withContext(Dispatchers.IO) {
            val queryIsLike = BaseDataBase.baseDataBase.ThemesDao().queryIsLike(data.titleName)
            if (queryIsLike != null) {
                BaseDataBase.baseDataBase.ThemesDao().delete(queryIsLike)
            }
        }

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

    }
}