package com.cheng.blzb.ui.fragment.mine.message

import androidx.collection.ArrayMap
import androidx.lifecycle.MutableLiveData
import com.cheng.blzb.bean.SubscriptionMessageEntity
import com.cheng.blzb.bean.UserAuthEntity
import com.cheng.blzb.net.ApiFactory
import com.cheng.blzb.net.model.toListResult
import com.example.base.extensions.toast
import com.example.base.utils.L
import com.example.base.viewmodel.ListViewModel

class MessageViewModel: ListViewModel<SubscriptionMessageEntity>() {
    override suspend fun requestApi(params: ArrayMap<String, String>): Result<List<SubscriptionMessageEntity>> {
        return ApiFactory.apiService.getSubscriptionMessage(params).toListResult()
    }

    val authLiveData = MutableLiveData<UserAuthEntity>()

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