package com.yzx.escreen.presenter

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

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


    fun getLeaveShowIds(student_id: String = "") {
        if (User.getUser().token.isEmpty()) {
            return
        }
        var url = "${Config.BASE_URL}${YzxInterface.INTERFACE_STUDENT_GET_SHOW_BOX_LIST}"
        if(student_id.isEmpty()){
            url = "${Config.BASE_URL}${YzxInterface.INTERFACE_STUDENT_GET_SHOW_BOX_LIST_OLD}"
        }
        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()
}