package com.cheng.blzb.ui.fragment.merchant.list

import androidx.collection.ArrayMap
import androidx.lifecycle.MutableLiveData
import com.cheng.blzb.bean.MerchantGoodsEntity
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 MerchantGoodsListViewModel: ListViewModel<MerchantGoodsEntity>() {
    override suspend fun requestApi(params: ArrayMap<String, String>): Result<List<MerchantGoodsEntity>> {
        return ApiFactory.apiService.searchGoods(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)
        })
    }
}