package com.yzx.ebrand.presenter

import com.blankj.utilcode.util.LogUtils
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import com.yzx.ebrand.config.Config
import com.yzx.ebrand.config.YzxInterface
import com.yzx.ebrand.model.LeaveID
import com.yzx.ebrand.model.User
import com.yzx.ebrand.presenter.base.BasePresenter
import com.yzx.ebrand.presenter.base.IView
import com.yzx.ebrand.presenter.base.JsonCallBack
import com.yzx.ebrand.presenter.base.YzxResponse

class MainPresenter(view: MainView) : BasePresenter<MainView>(view) {


    fun getLeaveShowIds(student_id: String = "") {
        if (User.getUser().token.isEmpty()) {
            return
        }
        val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_STUDENT_GET_SHOW_BOX_LIST}"
        OkGo.post<YzxResponse<LeaveID>>(url)
            .tag(this)
            .params("student_id", student_id)
            .execute(object : JsonCallBack<YzxResponse<LeaveID>>() {
                override fun onSuccess(response: Response<YzxResponse<LeaveID>>?) {
                    if (response?.isSuccessful == true) {
                        mView?.onLeaveIDsSuccess(response.body().list)
                        LogUtils.d("getLeaveShowIds", response.body().list)
                    }
                }

                override fun onError(response: Response<YzxResponse<LeaveID>>?) {
                    super.onError(response)
                    LogUtils.d(response)
                    mView?.onLeaveIDsError()
                }
            })
    }


}

interface MainView : IView {
    fun onLeaveIDsSuccess(list: MutableList<LeaveID>)
    fun onLeaveIDsError()
}