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.teacher.api.APIService;
import com.cooleshow.teacher.bean.MineLiveCourseListBean;
import com.cooleshow.teacher.bean.TeacherUserInfo;
import com.cooleshow.teacher.bean.request.LiveCourseEntry;
import com.cooleshow.teacher.contract.MineLiveCourseContract;

/**
 * 创建日期：2022/5/19 15:15
 *
 * @author Ryan
 * 类说明：
 */
public class MineLiveCoursePresenter extends BasePresenter<MineLiveCourseContract.MineLiveCourseView> implements MineLiveCourseContract.Presenter {
    public void queryPageCourseGroup(boolean isLoading, int page, String groupStatus) {
        if (isLoading && getView() != null) {
            getView().showLoading();
        }
        LiveCourseEntry entry = new LiveCourseEntry();
        entry.rows = Constants.DEFAULT_DATA_SIZE;
        entry.page = page;
        entry.groupStatus = groupStatus;
        addSubscribe(create(APIService.class).queryPageCourseGroup(entry), new BaseObserver<MineLiveCourseListBean>(getView()) {
            @Override
            protected void onSuccess(MineLiveCourseListBean data) {
                if (getView() != null) {
                    getView().queryPageCourseGroupSuccess(page, data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                getView().hideLoading();
            }

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