package com.zxhl.main.page.presenter

import android.util.Log
import com.zxhl.cms.common.Constant
import com.zxhl.cms.common.NetConfig
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.HomeBoxListEntity
import com.zxhl.cms.net.model.box.TabEntity
import com.zxhl.main.page.contract.NewPeopleContract

class NewPeoplePresenter : NewPeopleContract.Presenter {
    private val mView: NewPeopleContract.View


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

    override fun getBoxTab() {
        ApiClient.homeApi.getBoxTab().compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<List<TabEntity>>() {
                override fun onSuccess(result: List<TabEntity>?) {
                    if (result != null) {
                        mView.setTab(result)
                    }
                }

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

    override fun getNewBox() {
        if (Constant.Param.flowTag == "flow_tag_xymh_29") {
            ApiClient.homeApi.getNewPeopleBox29().compose(RxSchedulers.observableIO2Main())
                .subscribe(object : BaseObserver<HomeBoxListEntity>() {
                    override fun onSuccess(result: HomeBoxListEntity?) {
                        if (result != null) {
                            mView.setNewPeopleData(result)
                        }
                    }

                    override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                        Log.e("MXL", "ERROR" + code + errorMsg)
                    }
                })
        } else if (Constant.Param.flowTag == "flow_tag_xymh_24") {
            ApiClient.homeApi.getNewPeopleBox24().compose(RxSchedulers.observableIO2Main())
                .subscribe(object : BaseObserver<HomeBoxListEntity>() {
                    override fun onSuccess(result: HomeBoxListEntity?) {
                        if (result != null) {
                            mView.setNewPeopleData(result)
                        }
                    }

                    override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                        Log.e("MXL", "ERROR" + code + errorMsg)
                    }
                })
        } else {
            ApiClient.homeApi.getNewPeopleBox().compose(RxSchedulers.observableIO2Main())
                .subscribe(object : BaseObserver<HomeBoxListEntity>() {
                    override fun onSuccess(result: HomeBoxListEntity?) {
                        if (result != null) {
                            mView.setNewPeopleData(result)
                        }
                    }

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