package com.cheng.blzb.ui.fragment.push

import androidx.lifecycle.MutableLiveData
import com.cheng.blzb.bean.BidTypeEntity
import com.cheng.blzb.bean.SubscriptionEntity
import com.cheng.blzb.net.ApiFactory
import com.example.base.extensions.toast
import com.example.base.utils.L
import com.example.base.viewmodel.BaseViewModel

class PushViewModel : BaseViewModel() {
    val subscribeLiveData = MutableLiveData<List<SubscriptionEntity>>()
    val typeLiveData = MutableLiveData<List<BidTypeEntity>>()

    fun getSubscriptionList() {
        showDialog()
        launchOnUiTryCatch({
            val response = ApiFactory.apiService.getSubscriptionList()
            if (response.status) {
                subscribeLiveData.postValue(response.data.items)
            } else toast(response.message, true)
            dismissDialog()
        }, {
            dismissDialog()
            setError(it)
            L.d(it)
        })
    }

    fun getBidTypeList() {
        showDialog()
        launchOnUiTryCatch({
            val response = ApiFactory.apiService.getBidTypeList()
            if (response.status) {
                typeLiveData.postValue(response.data)
            } else toast(response.message, true)
            dismissDialog()
        }, {
            dismissDialog()
            setError(it)
            L.d(it)
        })
    }

}