package com.cooleshow.teacher.presenter.score;

import android.text.TextUtils;

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.MusicSheetListBean;
import com.cooleshow.teacher.contract.MineLiveCourseContract;
import com.cooleshow.teacher.contract.MineScoreContract;

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

/**
 * 创建日期：2022/5/20 16:48
 *
 * @author Ryan
 * 类说明：
 */
public class MineScorePresenter extends BasePresenter<MineScoreContract.MineScoreView> implements MineScoreContract.Presenter {
    public void queryPageCourseGroup(boolean isLoading, String subjectIds, String searchStr, int page, String auditStatus) {
        if (isLoading && getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            if (!TextUtils.isEmpty(subjectIds) && !TextUtils.equals(subjectIds, "0")) {
                //全部声部的时候不传这个字段
                jsonObject.put("subjectIds", subjectIds);
            }
            jsonObject.put("auditStatus", auditStatus);
            jsonObject.put("idAndName", searchStr);
            jsonObject.putOpt("page", page);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).queryMusicList(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<MusicSheetListBean>(getView()) {
            @Override
            protected void onSuccess(MusicSheetListBean data) {
                if (getView() != null) {
                    getView().queryMusicListSuccess(page, data);
                }
            }

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

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if (getView() != null) {
                    getView().queryMusicListError(page);
                }
            }
        });
    }


}
