package com.cheng.blzb.ui.fragment.bid.publish.bid

import androidx.collection.ArrayMap
import androidx.lifecycle.MutableLiveData
import com.cheng.blzb.bean.BidDetailEntity
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 MyBidViewModel: ListViewModel<BidDetailEntity>() {
    val deleteLiveData = MutableLiveData<Any>()

    override suspend fun requestApi(params: ArrayMap<String, String>): Result<List<BidDetailEntity>> {
        return ApiFactory.apiService.getMyBidList(params).toListResult()
    }

    fun deleteBid(id: String) {
        showDialog()
        launchOnUiTryCatch({
            val response = ApiFactory.apiService.deleteBidInfo(id)
            if (response.status) {
                deleteLiveData.postValue(Any())
            } else toast(response.message, true)
            dismissDialog()
        }, {
            dismissDialog()
            setError(it)
            L.d(it)
        })
    }
}