package com.adealink.weparty.room.member.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.adealink.frame.base.Rlt
import com.adealink.frame.base.fastLazy
import com.adealink.frame.mvvm.livedata.OnceMutableLiveData
import com.adealink.frame.mvvm.viewmodel.BaseViewModel
import com.adealink.weparty.App
import com.adealink.weparty.module.playmate.data.PlaymateCategoryData
import com.adealink.weparty.room.data.RoomPlaymateCategoryReq
import com.adealink.weparty.room.datasource.remote.RoomHttpService
import com.adealink.weparty.room.sdk.service.roomService
import kotlinx.coroutines.launch

class RoomPlaymateSkillViewModel : BaseViewModel() {

    private val roomHttpService by fastLazy {
        App.instance.networkService.getHttpService(RoomHttpService::class.java)
    }

    val skillListLD = MutableLiveData<List<PlaymateCategoryData>>()

    fun loadRoomPlaymateSkill(): LiveData<Rlt<Any>> {
        val liveData = OnceMutableLiveData<Rlt<Any>>()
        viewModelScope.launch {
            val roomId = roomService.joinController.getJoinedRoomId()
            if (roomId.isNullOrEmpty()) {
                return@launch
            }
            val rlt = roomHttpService.getRoomPlaymateCategory(RoomPlaymateCategoryReq(roomId))
            when (rlt) {
                is Rlt.Failed -> {
                    //Ntd.
                }

                is Rlt.Success -> {
                    skillListLD.send(rlt.data.data?.categorys ?: emptyList())
                }
            }
            liveData.send(rlt)
        }
        return liveData
    }


}