package com.adealink.weparty.playmate.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.adealink.frame.base.Rlt
import com.adealink.frame.mvvm.livedata.OnceMutableLiveData
import com.adealink.frame.mvvm.viewmodel.BaseViewModel
import com.adealink.weparty.module.playmate.data.PlaymateCategoryData
import com.adealink.weparty.module.playmate.data.UserPlaymateCategoryData
import com.adealink.weparty.module.playmate.viewmodel.IPlaymateViewModel
import com.adealink.weparty.playmate.manager.playmateManager
import kotlinx.coroutines.launch

class PlaymateViewModel : BaseViewModel(), IPlaymateViewModel {

    override val allCategoryLD = MutableLiveData<Map<String, PlaymateCategoryData>>()

    override fun pullAllCategory() {
        viewModelScope.launch {
            allCategoryLD.send(playmateManager.pullAllCategory())
        }
    }

    override fun getUserPlaymateCategory(
        uid: String,
        cache: Boolean
    ): LiveData<Rlt<List<UserPlaymateCategoryData>>> {
        val liveData = OnceMutableLiveData<Rlt<List<UserPlaymateCategoryData>>>()
        viewModelScope.launch {
            val rlt = playmateManager.getUserPlaymateCategory(uid, cache)
            liveData.send(rlt)
        }
        return liveData
    }

}