package com.zxbw.modulemain.box.presenter

import android.util.Log
import com.zxbw.modulemain.box.contract.OrderDetailContract
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.box.OrderEntity

class OrderDetailPresenter : OrderDetailContract.Presenter {
    private val mView: OrderDetailContract.View

    constructor(mView: OrderDetailContract.View) {
        this.mView = mView
    }

    override fun getShipping(depotIds: String,addressId:String?) {
        ApiClient.homeApi.getShipping(depotIds,addressId)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<OrderEntity>() {
                override fun onSuccess(result: OrderEntity?) {
                    mView.setOrderData(result)
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    Log.e("MXL","c"+code+errorMsg+e)
                }
            })
    }

    override fun createOrder(
        addressId: String?,
        depotIds: String?,
        orderNotes: String?,
        outTradeNo: String?
    ) {
        ApiClient.homeApi.createOrder(addressId,depotIds,orderNotes,outTradeNo)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<Any>() {
                override fun onSuccess(result: Any?) {
                    mView.creatOrderSucces()
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    Log.e("MXL","c"+code+errorMsg+e)
                }
            })
    }
}