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

import androidx.collection.ArrayMap
import androidx.lifecycle.MutableLiveData
import com.cheng.bole.bean.MerchantGoodsEntity
import com.cheng.bole.bean.UserAuthEntity
import com.cheng.bole.net.ApiFactory
import com.cheng.bole.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.searchSupplier(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)
        })
    }
}