package com.keypalette.theme.dataabout.database

import com.keypalette.theme.dataabout.resource.Data
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

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

    }

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

    }
}