package com.swago.baseswago

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

/**
 *@date 2022/2/7 10:32
 *description:
 */
class HandleVm(application: Application) : BaseViewModel(application) {

    val kickSuccessLiveData by lazy {
        MutableLiveData<Unit>()
    }

    val muteOrCancelLiveData by lazy {
        MutableLiveData<Int>()
    }

    val roomAuthLiveData by lazy {
        MutableLiveData<RoomAuthModel>()
    }


    fun getUserRoomAuth(userId: String, roomId: String) {
        requestData {
            roomAuthLiveData.value = ApiManager.roomApi.getUserRoomAuth(roomId,userId)
        }
    }

    fun kickOutRoom(userId: String, roomId: String,type:Int) {
        requestData {
            ApiManager.roomApi.kickUserFromRoom(roomId, userId,type)
            if (type==1){
                Toast.makeText(
                    AppContext.getContext(),
                    AppContext.getContext().resources.getString(R.string.kick_success),
                    Toast.LENGTH_SHORT
                ).show()
            }else{
                Toast.makeText(
                    AppContext.getContext(),
                    AppContext.getContext().resources.getString(R.string.cancel_black_success),
                    Toast.LENGTH_SHORT
                ).show()
            }

            kickSuccessLiveData.value = Unit
        }
    }


    fun muteOrCancel(userId: String, roomId: String, type: Int) {
        requestData {
            ApiManager.roomApi.muteUerFromRoom(roomId, userId, type)
            if (type == 1) {
                Toast.makeText(
                    AppContext.getContext(),
                    AppContext.getContext().resources.getString(R.string.mute_success),
                    Toast.LENGTH_SHORT
                ).show()
            } else if (type == 0) {
                Toast.makeText(
                    AppContext.getContext(),
                    AppContext.getContext().resources.getString(R.string.cancel_mute_success),
                    Toast.LENGTH_SHORT
                ).show()
            }
            muteOrCancelLiveData.value = type
        }
    }



    val blackTypeLiveData by lazy {
        MutableLiveData<Int>()
    }
    /**
     * 拉黑
     */
    fun blackUser(userId: String,blackType:Int,type:Int){
        requestData {
            ApiManager.roomApi.blackUser(userId,blackType,type)
            when(type){
              1 -> {
                  Toast.makeText(AppContext.getContext(), AppContext.getContext().resources.getString(R.string.black_success), Toast.LENGTH_SHORT).show()
              }
              0 -> {
                  Toast.makeText(AppContext.getContext(), AppContext.getContext().resources.getString(R.string.cancel_black_success), Toast.LENGTH_SHORT).show()
              }
            }
            blackTypeLiveData.value = blackType
        }
    }

}