package com.ym.game.presenter

import com.tencent.ep.commonbase.api.AppContext
import com.ym.game.contract.WelfareContract
import com.ym.library.module.*
import com.ym.library.net.BaseObserver
import com.ym.library.net.GameApiClient
import com.ym.library.net.RxSchedulers
import com.ym.library.utils.Utils

class WelfarePresenter : WelfareContract.Presenter {

    var mView: WelfareContract.View

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

    override fun getDiamondList() {
        GameApiClient.gameApi.getTaskProcess().compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<DiamondEntity>() {
            override fun onSuccess(result: DiamondEntity?) {
                mView?.diamondListResult(result)
            }

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

    override fun getTaskList() {
        GameApiClient.gameApi.getTaskListInfo("welfare_center_task_list").compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<TaskListEntity>() {
            override fun onSuccess(result: TaskListEntity?) {
                mView?.taskListResult(result)
            }

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

    override fun getTaskReceiveList(sid: Int) {
        GameApiClient.gameApi.getTaskComplete(sid).compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<TaskCompleteEntity>() {
            override fun onSuccess(result: TaskCompleteEntity?) {
                mView?.taskReceiveListResult(result)
            }

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

    override fun getWelfareVideoReport(sid: Int) {
        GameApiClient.gameApi.getWelfareVideoReport(sid).compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<NewsEntity>() {
            override fun onSuccess(result: NewsEntity?) {
                getTaskList()
            }

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

    override fun getWelfareTaskBox() {
        GameApiClient.gameApi.getWelfareTaskBox().compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<List<FlyBoxEntity>>() {
            override fun onSuccess(result: List<FlyBoxEntity>?) {
                mView?.taskCashResult(result)
            }

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

    fun getWelfareTaskCash() {
        GameApiClient.gameApi.getWelfareTaskCash().compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<ExchangeEntity>() {
            override fun onSuccess(result: ExchangeEntity?) {
                mView?.welfareTaskCashResult(result)
            }

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


    fun getADShowTimer(){
        GameApiClient.gameApi.getAdTimeCD("WELFARE_TASK").compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<StatusEntity>() {
            override fun onSuccess(result: StatusEntity?) {
                mView?.taskTimeCd(result?.cd)
            }

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




}