package com.zxbw.modulemain.presenter

import com.zxbw.modulemain.contract.SearchContract
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.qy.TbGoodsEntity

class SearchPresenter : SearchContract.Presenter {
    private val mView: SearchContract.View


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

    override fun getSearchHistory() {
        mView.setSearchHistory()
    }

    override fun getBestGoodsList() {
        ApiClient.homeApi.getGoodsGuessLike(1, 9)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<TbGoodsEntity>() {
                override fun onSuccess(result: TbGoodsEntity?) {
                    mView.setBestGoodsList(result?.data)
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    mView.setBestGoodsList(null)
                }
            })
    }

}