package com.mints.goodmoney.mvp.presenters

import com.google.gson.JsonObject
import com.mints.goodmoney.manager.AppHttpManager
import com.mints.goodmoney.mvp.model.BaseResponse
import com.mints.goodmoney.mvp.model.FriendHallMsgBean
import com.mints.goodmoney.mvp.views.FriendsView
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable

class FriendsPresenter : BasePresenter<FriendsView>() {

    /**
     * 世界人民排名
     */
//    fun getLeaders() {
//        AppHttpManager.getInstance(loanApplication)
//                .call(loanService.leaders, object : BaseSubscriber<BaseResponse<FriendsTaskBean.FriendsBean>>() {
//                    override fun onCompleted() {
//                        if (isLinkView) return
//                    }
//
//                    override fun onError(e: Throwable) {
//                        if (isLinkView) return
//                    }
//
//                    override fun onNext(baseResponse: BaseResponse<FriendsTaskBean.FriendsBean>) {
//                        if (isLinkView) return
//                        when (baseResponse.status) {
//                            200 -> view.getWorldRankSuc(baseResponse.data)
//                        }
//                    }
//                })
//    }

    /**
     * 好友任务
     */
//    fun getFriendsMsg() {
//        AppHttpManager.getInstance(loanApplication)
//                .call(loanService.friendsMsg, object : BaseSubscriber<BaseResponse<FriendsTaskBean>>() {
//                    override fun onCompleted() {
//                        if (isLinkView) return
//                    }
//
//                    override fun onError(e: Throwable) {
//                        if (isLinkView) return
//                    }
//
//                    override fun onNext(baseResponse: BaseResponse<FriendsTaskBean>) {
//                        if (isLinkView) return
//                        when (baseResponse.status) {
//                            200 -> {
//                                view.getFriendsRankSuc(baseResponse.data)
//                            }
//                        }
//                    }
//                })
//    }

    /**
     * 分红奖励信息
     */
    fun getFriendHallMsg() {
        view.showLoading("加载中...")
        AppHttpManager.getInstance(loanApplication)
                .call(loanService.friendHallMsg(), object : BaseSubscriber<BaseResponse<FriendHallMsgBean>>() {
                    override fun onCompleted() {
                        if (isLinkView) return
                        view.hideLoading()
                    }

                    override fun onError(e: Throwable) {
                        if (isLinkView) return
                        view.hideLoading()
                    }

                    override fun onNext(baseResponse: BaseResponse<FriendHallMsgBean>) {
                        if (isLinkView) return
                        view.hideLoading()

                        when (baseResponse.status) {
                            200 -> {
                                view.getFriendsHallMsgSuc(baseResponse.data)
                            }
                            else -> {
                                view.showToast("网络出小差儿了")
                            }
                        }
                    }
                })
    }

    /**
     * 贡献榜单数据
     */
    fun getContributionLeaders() {
        view.showLoading("加载中...")
        AppHttpManager.getInstance(loanApplication)
                .call(loanService.contributionLeaders(), object : BaseSubscriber<BaseResponse<FriendHallMsgBean>>() {
                    override fun onCompleted() {
                        if (isLinkView) return
                        view.hideLoading()
                    }

                    override fun onError(e: Throwable) {
                        if (isLinkView) return
                        view.hideLoading()
                    }

                    override fun onNext(baseResponse: BaseResponse<FriendHallMsgBean>) {
                        if (isLinkView) return
                        view.hideLoading()

                        when (baseResponse.status) {
                            200 -> {
                                view.getContributionLeadersSuc(baseResponse.data)
                            }
                            else -> {
                                view.showToast(baseResponse.message)
                            }
                        }
                    }
                })
    }

    /**
     * 贡献榜单数据
     */
    fun getContributionOutToCash() {
        view.showLoading("加载中...")
        AppHttpManager.getInstance(loanApplication)
                .call(loanService.contributionOutToCash(), object : BaseSubscriber<BaseResponse<JsonObject>>() {
                    override fun onCompleted() {
                        if (isLinkView) return
                        view.hideLoading()
                    }

                    override fun onError(e: Throwable) {
                        if (isLinkView) return
                        view.hideLoading()
                    }

                    override fun onNext(baseResponse: BaseResponse<JsonObject>) {
                        if (isLinkView) return
                        view.hideLoading()

                        when (baseResponse.status) {
                            200 -> {
                                view.getContributionOutToCashSuc()
                            }
                            else -> {
                                view.showToast(baseResponse.message)
                            }
                        }
                    }
                })
    }

    /**
     * 设置邀请成功
     *
     */
//    fun cmtShareStatus() {
//        val vo = HashMap<String, Any>()
//        vo["carrierType"] = Constant.CHALLENGE_SHAREFRIEND
//        vo["value"] = "1"
//        AppHttpManager.getInstance(loanApplication)
//                .call(loanService.setStatusInOneDayByCarrierType(vo), object : BaseSubscriber<BaseResponse<Any>>() {
//                    override fun onCompleted() {
//                        if (isLinkView) return
//                    }
//
//                    override fun onError(e: Throwable) {
//                        if (isLinkView) return
//                    }
//
//                    override fun onNext(baseResponse: BaseResponse<Any>) {
//                        if (isLinkView) return
//                        when (baseResponse.status) {
//                                    200 -> baseMsg()
//                        }
//                    }
//                })
//    }


}