package com.rich.keyboard.skin.db

import com.rich.keyboard.skin.localdata.Child
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

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

    }

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

    }
}