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

/**
 * 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();
        }
        LiveCourseEntry entry = new LiveCourseEntry();
        entry.classDate =month;
        entry.rows =Constants.DEFAULT_DATA_SIZE;
        entry.page =page;
        entry.groupStatus ="apply";
        addSubscribe(create(APIService.class).queryPageCourseGroup(entry), 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);
                }
            }
        });
    }
}
