package com.color.keyboard.black.database

import com.color.keyboard.black.bean.ChildData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object DbHelper {


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

    }



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

    }
}