package com.ym.game.presenter

import com.ym.game.contract.SpeedWaterContract
import com.ym.library.module.NewsEntity
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

class SpeedWaterPresenter : SpeedWaterContract.Presenter {
    var mView: SpeedWaterContract.View

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

    override fun getAcceleratorsTask() {
//        GameApiClient.gameApi.getAcceleratorsTask().compose(
//            RxSchedulers.observableIO2Main()
//        ).subscribe(object : BaseObserver<List<WateringTaskEntity>>() {
//            override fun onSuccess(result: List<WateringTaskEntity>?) {
//                if (result != null) {
//                    mView?.AcceleratorsTaskResult(result)
//                }
//            }
//
//            override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {}
//        })
//    }
        GameApiClient.gameApi.getTaskListInfo("watter_high_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 getTaskComplete(sid: Int) {
        GameApiClient.gameApi.getWelfareVideoReport(sid).compose(
            RxSchedulers.observableIO2Main()
        ).subscribe(object : BaseObserver<NewsEntity>() {
            override fun onSuccess(result: NewsEntity?) {
                getAcceleratorsTask()
            }

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

            }
        })
    }
}