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.TeacherUserInfo;
import com.cooleshow.teacher.bean.VideoCourseListBean;
import com.cooleshow.teacher.contract.LiveCoursePageContract;
import com.cooleshow.teacher.contract.VideoCoursePageContract;

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

/**
 * 创建日期：2022/6/7 9:40
 *
 * @author Ryan
 * 类说明：
 */
public class VideoCoursePagePresenter extends BasePresenter<VideoCoursePageContract.VideoCoursePageView> implements VideoCoursePageContract.Presenter {
    public void queryVideoCourseGroup(boolean isLoading, int page) {
        if (isLoading && getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("auditStatus","PASS");
            jsonObject.putOpt("page", page);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).getVideoCourses(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<VideoCourseListBean>(getView()) {
            @Override
            protected void onSuccess(VideoCourseListBean data) {
                if (getView() != null) {
                    getView().queryVideoCourseGroupSuccess(page, data);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if (getView() != null) {
                    getView().queryVideoCourseGroupError(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);
                }
            }
        });
    }
}
