package com.app.brush.guitar.ink.ballad

import com.app.brush.guitar.ink.drama.DichotomyDetails
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object Gratitude {


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

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

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

    }
}