package com.adealink.weparty.profile.dialog.viewmodel

import androidx.lifecycle.LiveData
import com.adealink.frame.base.Rlt
import com.adealink.frame.mvvm.livedata.OnceMutableLiveData
import com.adealink.frame.mvvm.viewmodel.BaseViewModel
import com.adealink.weparty.App
import com.adealink.weparty.commonui.ext.isSuccess
import com.adealink.weparty.profile.data.PlaymateCharmStarReq
import com.adealink.weparty.profile.datasource.remote.ProfileHttpService
import com.adealink.weparty.profile.manager.profileManager
import kotlinx.coroutines.launch

class PlaymateCharmStarViewModel : BaseViewModel() {

    private val profileHttpService by lazy {
        App.instance.networkService.getHttpService(ProfileHttpService::class.java)
    }

    fun charmStar(uid: String, star: Float): LiveData<Rlt<Any>> {
        val liveData = OnceMutableLiveData<Rlt<Any>>()
        viewModelScope.launch {
            val rlt = profileHttpService.playmateCharmStar(PlaymateCharmStarReq(uid, star))
            if (rlt.isSuccess) {
                profileManager.getUserInfoByUid(uid, false)
            }
            liveData.send(rlt)
        }
        return liveData
    }
}