package com.duben.microtribe.mvp.presenters

import com.duben.microtribe.manager.AppHttpManager
import com.duben.microtribe.mvp.model.BaseResponse
import com.duben.microtribe.mvp.views.BackCashView
import com.duben.library.net.neterror.BaseSubscriber
import com.duben.library.net.neterror.Throwable
import java.util.HashMap

class BackCashPresenter : BasePresenter<BackCashView>() {

    fun reqfundV1(
        orderMobile: String,
        orderCause: String,
        orderSuggest: String,
        orderNickname: String,
    ) {
        val vo = HashMap<String, Any>()
        vo["reason"] = orderCause
        vo["mobile"] = orderMobile
        vo["name"] = orderNickname
        vo["remarks"] = orderSuggest
        AppHttpManager.getInstance(loanApplication)
            .call(loanService.reqfundV1(vo),
                object : BaseSubscriber<BaseResponse<Any>>() {
                    override fun onCompleted() {
                        if (isLinkView) return
                        view.hideLoading()
                    }

                    override fun onError(e: Throwable) {
                        if (isLinkView) return
                        view.hideLoading()
                        view.reqfundFail(e.message.toString())
                    }

                    override fun onNext(baseResponse: BaseResponse<Any>) {
                        if (isLinkView) return
                        val code: Int = baseResponse.status
                        when (code) {
                            200 -> {
                                view.reqfundSuc()
                            }
                            else -> {
                                view.reqfundFail(baseResponse.message)
                            }
                        }
                    }
                })
    }
}