package com.cooleshow.teacher.presenter.homePage;

import com.cooleshow.base.constanst.Constants;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.bean.SparringCourseListBean;
import com.cooleshow.teacher.bean.TeacherUserInfo;
import com.cooleshow.teacher.bean.request.TeacherPracticeCourseEntry;
import com.cooleshow.teacher.contract.SparringCoursePageContract;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 创建日期：2022/6/6 17:41
 *
 * @author Ryan
 * 类说明：
 */
public class SparringCoursePagePresenter extends BasePresenter<SparringCoursePageContract.SparringCoursePageView> implements SparringCoursePageContract.Presenter {

    public void querySparringCourse(int page,String currentData) {
        if (getView() != null) {
            getView().showLoading();
        }
        TeacherPracticeCourseEntry entry = new TeacherPracticeCourseEntry();
        entry.page = page;
        entry.rows = Constants.DEFAULT_DATA_SIZE;
        entry.classMonth= currentData;
        addSubscribe(create(APIService.class).getSparringCourses(entry), new BaseObserver<SparringCourseListBean>(getView()) {
            @Override
            protected void onSuccess(SparringCourseListBean data) {
                if (getView() != null) {
                    getView().onGetSparringCourseSuccess(page, data);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if (getView() != null) {
                    getView().onGetCourseError(page);
                }
            }
        });
    }

    public void getTeacherUserInfo() {
        addSubscribe(create(APIService.class).getTeacherUserInfo(), new BaseObserver<TeacherUserInfo>(getView()) {
            @Override
            protected void onSuccess(TeacherUserInfo data) {
                if (getView() != null) {
                    getView().getTeacherInfoSuccess(data);
                }
            }
        });
    }
}
