package com.bc_chat.mine.presenter

import com.bc_chat.bc_base.presenter.UpLoadPicturePresenter
import com.bc_chat.mine.contract.FeedbackContract
import com.bc_chat.mine.task.FeedbackTask
import com.google.gson.JsonObject
import com.zhaohaoting.framework.requset.NetWorkCallBack
import com.zhaohaoting.framework.utils.Utils
import java.lang.Exception

/**
 * author：Created by zhaohaoting on 2019/3/19
 * email：526309416@qq.com
 * desc：
 */
class FeedbackPresenter(view: FeedbackContract.View) : UpLoadPicturePresenter<FeedbackContract.View>(view), FeedbackContract.Presenter {

    override fun feedback(paths: MutableList<String>?, content: String, phone: String) {
        val path = if (Utils.listIsEmpty(paths)) {
            ""
        } else {
            paths!![0]
        }
        taskHelper.execute<Any>(FeedbackTask(path, content, phone), object : NetWorkCallBack<JsonObject>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

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

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