package com.swago.room.vm

import android.app.Application
import android.widget.Toast
import androidx.lifecycle.MutableLiveData
import com.swago.baseswago.inter.ApiManager
import com.swago.baseswago.model.live.RankListModel
import com.swago.baseswago.model.live.game.GameListModel
import com.swago.baseswago.util.AppContext
import com.swago.baseswago.util.BaseViewModel

/**
 *@date 2021/12/1 20:24
 *description:
 */
class RoomOtherVm (application: Application) : BaseViewModel(application){

    val rankListLiveData by lazy {
        MutableLiveData<List<RankListModel.ListBean>?>()
    }

    val gameListModelLiveData by lazy {
        MutableLiveData<GameListModel>()
    }

    val totalLiveData by lazy {
        MutableLiveData<String>()
    }

    fun getGameList(){
        requestData {
            gameListModelLiveData.value = ApiManager.roomApi.getGameList()
        }
    }


    fun getRankList(roomId:String,rankType:Int,page:Int){
        requestData2 {
            requestData {
                val data = ApiManager.roomApi.getRankList(roomId,rankType,page)
                rankListLiveData.value = data.list
                totalLiveData.value = data.total
            }

            requestError {
                Toast.makeText(AppContext.getContext(), it.message, Toast.LENGTH_SHORT).show()
                rankListLiveData.value = null
            }
        }
    }

}