package com.app.intelligent.board.uidb

import com.app.intelligent.board.uimodel.KeyboardItemInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object MyAppDatabaseManager {


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

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

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

    }
}