package com.keyboard.skinning.cool.db

import com.keyboard.skinning.cool.data.ChildData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object DbFunction {


    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)
            }
        }

    }
}