package com.app.input.breeze.board.database

import com.app.input.breeze.board.bean.KeyboardTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

object FavoriteRepository {


    suspend fun addLike(data: KeyboardTheme) {
        withContext(Dispatchers.IO) {
            AppDatabase.instance.favoriteThemeDao().insertData(data)
        }

    }
    suspend fun removeLike(data: KeyboardTheme) {
        withContext(Dispatchers.IO) {
            val queryIsLike = AppDatabase.instance.favoriteThemeDao().queryIsLike(data.titleName)
            if (queryIsLike != null) {
                AppDatabase.instance.favoriteThemeDao().delete(queryIsLike)
            }
        }

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

    }
}