package com.bc_chat.bc_base.presenter

import com.bc_chat.bc_base.contract.PayPasswordContract
import com.bc_chat.bc_base.task.PayPasswordIsSetTask
import com.bc_chat.bc_base.task.PayPasswordModifyTask
import com.bc_chat.bc_base.task.PayPasswordSetTask
import com.google.gson.JsonObject
import com.zhaohaoting.framework.abs.presenter.BasePresenter
import com.zhaohaoting.framework.requset.NetWorkCallBack

/**
 * author：Created by zhaohaoting on 2019/7/19
 * email：526309416@qq.com
 * desc：
 */
class PayPasswordPresenter<VIEW : PayPasswordContract.View>(view: VIEW) : BasePresenter<VIEW>(view), PayPasswordContract.Presenter {

    override fun editPayKey(old_pay_key: String, new_pay_key: String) {
        taskHelper.execute<Any>(PayPasswordModifyTask(old_pay_key, new_pay_key), object : NetWorkCallBack<JsonObject>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

            override fun onPostExecuteSuccess(task: Any?, data: JsonObject?) {
                view.dismissLoading(task)
                view.editPayKeySuccess();
            }

            override fun onPostExecuteFailure(task: Any?, exception: Exception?) {
                super.onPostExecuteFailure(task, exception)
                view.dismissLoading(task)
                view.editPayKeyFailure(exception)
            }
        })
    }

    override fun setPayKey(pay_key: String) {
        taskHelper.execute<Any>(PayPasswordSetTask(pay_key), object : NetWorkCallBack<JsonObject>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

            override fun onPostExecuteSuccess(task: Any?, data: JsonObject?) {
                view.dismissLoading(task)
                view.setPayKeySuccess();
            }

            override fun onPostExecuteFailure(task: Any?, exception: Exception?) {
                super.onPostExecuteFailure(task, exception)
                view.dismissLoading(task)
                view.setPayKeyFailure(exception)
            }
        })
    }

}
