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.model.TeacherInfo
import com.yzx.ebrand.model.User
import com.yzx.ebrand.config.YzxInterface
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 MyPresenter(view: MyView) : BasePresenter<MyView>(view) {


    fun getTeacherInfo(user_id: Int) {
        if(User.getUser().token.isEmpty()){
            return
        }
        val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_GET_TEACHER_INFO}"
        OkGo.post<YzxResponse<TeacherInfo>>(url)
            .tag(this)
            .params("user_id", user_id)
            .execute(object : JsonCallBack<YzxResponse<TeacherInfo>>() {

                override fun onSuccess(response: Response<YzxResponse<TeacherInfo>>?) {
                    LogUtils.d(response)
                    if (response?.isSuccessful == true) {
                        mView?.onUserInfoSuccess(response.body().data)
                    }
                }

                override fun onError(response: Response<YzxResponse<TeacherInfo>>?) {
                    super.onError(response)
                    LogUtils.d(response)
                    mView?.onUserInfoError(response?.body()?.msg ?: "")
                }
            })
    }




}

interface MyView : IView {
    fun onUserInfoSuccess(info: TeacherInfo)
    fun onUserInfoError(error:String)
}