package com.keyboard.keyboardtheme.skin.datamanager.db

import com.keyboard.keyboardtheme.skin.datamanager.localdata.Child
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object DbManager {
    suspend fun addLike(data: Child) {
        withContext(Dispatchers.IO) {
            RoomBase.myroom.ThemesDao().insertData(data)
        }

    }

    suspend fun removeLike(data: Child) {
        withContext(Dispatchers.IO) {
            val queryIsLike = RoomBase.myroom.ThemesDao().queryIsLike(data.titleName)
            if (queryIsLike != null) {
                RoomBase.myroom.ThemesDao().delete(queryIsLike)
            }
        }

    }


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

    }
}