package com.zxbw.modulemain.box.presenter

import android.util.Log
import com.zxbw.modulemain.box.contract.ShopOrderContract
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 ShopOrderPresenter: ShopOrderContract.Presenter {
    private val mView: ShopOrderContract.View

    constructor(mView: ShopOrderContract.View) {
        this.mView = mView
    }
    override fun createOrder(
        addressId: String?,
        depotIds: String?,
        orderNotes: String?
    ) {
        ApiClient.homeApi.shopBuyOnly(addressId,depotIds,orderNotes)
            .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)
                }
            })
    }

    override fun getShopCost(depotIds: String, addressId: String?) {
        ApiClient.homeApi.getshopCost(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)
                }
            })
    }
}