package com.key.board.journey.inputmethod.mydata

import com.key.board.journey.inputmethod.data.ChildBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object DbHelper {


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

    }



    suspend fun removeLike(data: ChildBean) {
        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)
            }
        }

    }
}