package com.common.im.presenter;

import com.common.im.api.IMApi;
import com.common.im.bean.MusicSheetListBean;
import com.common.im.contract.SelectScoreChatContract;
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 org.json.JSONException;
import org.json.JSONObject;

/**
 * 创建日期：2022/6/10 15:31
 *
 * @author Ryan
 * 类说明：
 */
public class SelectScoreChatPresenter extends BasePresenter<SelectScoreChatContract.SelectScoreChatView> implements SelectScoreChatContract.Presenter {
    public void queryPageCourseGroup(boolean isLoading, int page, String auditStatus,String search) {
        if (isLoading && getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("auditStatus", auditStatus);
            jsonObject.put("search", search);
            jsonObject.putOpt("page", page);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(IMApi.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 onError(Throwable e) {
                super.onError(e);
                if (getView() != null) {
                    getView().queryMusicListError(page);
                }
            }
        });
    }
}
