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.LiveCourseListBean;
import com.cooleshow.teacher.bean.MineLiveCourseListBean;
import com.cooleshow.teacher.bean.TeacherSelfStyleInfoBean;
import com.cooleshow.teacher.bean.TeacherUserInfo;
import com.cooleshow.teacher.contract.LiveCoursePageContract;
import com.cooleshow.teacher.contract.MineStyleContract;
import com.cooleshow.usercenter.bean.UserInfo;

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

/**
 * Author by pq, Date on 2022/4/20.
 */
public class LiveCoursePagePresenter extends BasePresenter<LiveCoursePageContract.LiveCoursePageView> implements LiveCoursePageContract.Presenter {

    public void queryLiveCourse(  String month,int page) {
        if (getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("classDate", month);
            jsonObject.putOpt("page", page);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).queryPageCourseGroup(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<MineLiveCourseListBean>(getView()) {
            @Override
            protected void onSuccess(MineLiveCourseListBean data) {
                if (getView() != null) {
                    getView().onGetLiveCourseSuccess(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);
                }
            }
        });
    }
}
