package com.ym.game.presenter

import com.ym.game.contract.WateringRewardContract
import com.ym.library.module.NewsEntity
import com.ym.library.module.SinginEntity
import com.ym.library.module.TaskListEntity
import com.ym.library.module.WateringTaskEntity
import com.ym.library.net.BaseObserver
import com.ym.library.net.GameApiClient
import com.ym.library.net.RxSchedulers
import com.ym.library.utils.LogUtils

/**
 *Craeted by ${junqi.li}
 *Craeted by 2020/9/12
 */
class WateringRewardPresenter : WateringRewardContract.Presenter {

    var mView: WateringRewardContract.View

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

    //任务
    override fun getRrchardDailyTask() {
//        GameApiClient.gameApi.getOrchardDailyTask().compose(
//            RxSchedulers.observableIO2Main()
//        ).subscribe(object : BaseObserver<List<WateringTaskEntity>>() {
//            override fun onSuccess(result: List<WateringTaskEntity>?) {
//                if (result != null) {
//                    mView?.rchardDailyTaskResult(result)
//                }
//            }
//
//            override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {}
//        })
        GameApiClient.gameApi.getTaskListInfo("coin_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 getOrchardSignTask() {
        GameApiClient.gameApi.getOrchardSignTask().compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<SinginEntity>() {
            override fun onSuccess(result: SinginEntity?) {
                if (result != null) {
                    mView?.rchardSignTaskResult(result)
                }
            }

            override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                LogUtils.i("Popupwindow", errorMsg)
            }
        })
    }

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

            override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                getRrchardDailyTask()

            }
        })
    }


}