package com.cooleshow.teacher.presenter.score;

import com.cooleshow.base.data.net.ApiException;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.base.utils.ToastUtils;
import com.cooleshow.base.utils.ErrorParse;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.bean.MusicSheetShareBean;
import com.cooleshow.teacher.bean.QuerySubjectBean;
import com.cooleshow.teacher.contract.MineScoreActContract;

import java.util.List;

/**
 * 创建日期：2022/5/23 10:24
 *
 * @author Ryan
 * 类说明：
 */
public class MineScoreActPresenter extends BasePresenter<MineScoreActContract.MineScoreActView> implements MineScoreActContract.Presenter {

    public void musicSheetShare() {
        getView().showLoading();
        addSubscribe(create(APIService.class).musicSheetShare(), new BaseObserver<MusicSheetShareBean>(getView()) {
            @Override
            protected void onSuccess(MusicSheetShareBean data) {
                if (getView() != null) {
                    getView().musicSheetShareSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                getView().hideLoading();
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if (e instanceof ApiException) {
                    ErrorParse.getInstance().parseError(e);
                    ApiException apiException = (ApiException) e;
                    ToastUtil.getInstance().showShort(apiException.getErrmsg());
                }
            }
        });
    }

    /**
     * 查询声部信息
     */
    public void querySubjectItem() {
        addSubscribe(create(APIService.class).querySubjectItem(), new BaseObserver<List<QuerySubjectBean>>(getView()) {
            @Override
            protected void onSuccess(List<QuerySubjectBean> data) {
                if (getView() != null) {
                    getView().querySubjectItemSuccess(data);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);

            }
        });
    }
}
