package com.duben.microtribe.mvp.presenters

import com.duben.microtribe.manager.AppHttpManager
import com.duben.microtribe.mvp.model.BaseResponse
import com.duben.microtribe.mvp.views.PicContentView
import com.duben.library.net.neterror.BaseSubscriber
import com.duben.library.net.neterror.Throwable
import com.duben.microtribe.mvp.model.BannerList

class PicContentPresenter : BasePresenter<PicContentView>() {

    fun getHomePageImageList(typeId: Int, page: Int, pageCount: Int) {
        val vo = hashMapOf<String, Any>()
        vo["typeId"] = typeId
        vo["page"] = page
        vo["size"] = pageCount

        AppHttpManager.getInstance(loanApplication)
            .call(loanService.getHomeV1List(vo),
                object : BaseSubscriber<BaseResponse<BannerList>>() {
                    override fun onCompleted() {
                        if (isLinkView) return
                    }

                    override fun onError(e: Throwable) {
                        if (isLinkView) return
                        view.showToast(e.message)
                        view.getHomePageImageListFail()
                    }

                    override fun onNext(baseResponse: BaseResponse<BannerList>) {
                        if (isLinkView) return

                        val code = baseResponse.status
                        val message = baseResponse.message

                        when (code) {
                            200 -> {
                                view.getHomePageImageListSuc(baseResponse.data)
                            }
                            else -> {
                                view.showToast(message)
                                view.getHomePageImageListFail()
                            }
                        }
                    }
                })
    }


}