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

import androidx.collection.ArrayMap
import androidx.lifecycle.MutableLiveData
import com.cheng.bole.bean.BidItemBean
import com.cheng.bole.bean.UserAuthBean
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 SearchListViewModel: ListViewModel<BidItemBean>() {
    override suspend fun requestApi(params: ArrayMap<String, String>): Result<List<BidItemBean>> {
        return ApiFactory.apiService.search(params).toListResult()
    }

    val authLiveData = MutableLiveData<UserAuthBean>()

    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)
        })
    }
}