package com.cooleshow.teacher.presenter.course;

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.MineLiveCourseListBean;
import com.cooleshow.teacher.bean.MineVideoCourseListBean;
import com.cooleshow.teacher.bean.TeacherUserInfo;
import com.cooleshow.teacher.bean.VideoCourseListBean;
import com.cooleshow.teacher.contract.MineLiveCourseContract;
import com.cooleshow.teacher.contract.MineVideoCourseContract;

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

/**
 * 创建日期：2022/5/20 13:50
 *
 * @author Ryan
 * 类说明：
 */
public class MineVideoCoursePresenter extends BasePresenter<MineVideoCourseContract.MineVideoCourseView> implements MineVideoCourseContract.Presenter {
    public void queryVideoCourseGroup(boolean isLoading, int page, String auditStatus) {
        if (isLoading && getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("auditStatus", auditStatus);
            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);
                }
            }
        });
    }


}
