package com.zxbw.modulemain.presenter

import android.util.Log
import com.zxbw.modulemain.contract.BoxOrderContract
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.NoticeEntity
import com.zxhl.cms.net.model.box.ShopOrderEntity

class BoxOrderPresenter : BoxOrderContract.Presenter {
    private val mView: BoxOrderContract.View


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

    private var page: Int = 1
    private val size: Int = 10
    override fun getOrderList(ifRefresh: Boolean) {
        if (ifRefresh) {
            page = 1
        }
        ApiClient.homeApi.getOrder(page, size)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<List<ShopOrderEntity>>() {
                override fun onSuccess(result: List<ShopOrderEntity>?) {
                    if (result != null) {
                        page++;
                        mView.setOrderListData(ifRefresh, result)
                    } else {
                        mView.setOrderListData(ifRefresh, null)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    Log.d("wxw", "goodsListError " + code + " errorMsg " + errorMsg)
                    mView.setOrderListData(ifRefresh, null)
                }
            })

    }

    override fun getNotice() {
        ApiClient.homeApi.getNotice()
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<NoticeEntity>() {
                override fun onSuccess(result: NoticeEntity?) {

                    mView.setNotice(result)

                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }


}