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.base.utils.RequestBodyUtil;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.bean.HomePageSheetMusicListBean;
import com.cooleshow.teacher.bean.TeacherSelfStyleInfoBean;
import com.cooleshow.teacher.contract.LiveCoursePageContract;
import com.cooleshow.teacher.contract.SheetMusicPageContract;
import com.cooleshow.usercenter.bean.UserInfo;

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

/**
 * Author by pq, Date on 2022/4/20.
 */
public class SheetMusicPagePresenter extends BasePresenter<SheetMusicPageContract.SheetMusicPageView> implements SheetMusicPageContract.Presenter {
    //DOING:待审核;PASS:通过;UNPASS:未通过
    public static final String SHEET_MUSIC_STATUS_PASS = "PASS";//曲目审核状态PASS

    /**
     * 查询UserInfo
     *
     * @param
     */
    public void getUserInfo() {
        addSubscribe(create(APIService.class).getUserInfo(), new BaseObserver<UserInfo>(getView()) {
            @Override
            protected void onSuccess(UserInfo data) {
//                if (getView() != null) {
//                    getView().getUserInfoSuccess(data);
//                }
            }
        });
    }

    /**
     * 老师个人主页->曲谱列表
     */
    public void getSheetMusicList(boolean isShowLoading, int page) {
        if (isShowLoading && getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("auditStatus", SHEET_MUSIC_STATUS_PASS);//0：停用，1：启用
            jsonObject.putOpt("page", page);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        addSubscribe(create(APIService.class).getSheetMusicList(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<HomePageSheetMusicListBean>(getView()) {
            @Override
            protected void onSuccess(HomePageSheetMusicListBean data) {
                if (getView() != null) {
                    getView().getSheetMusicListSuccess(page, data);
                }
            }

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