package com.cooleshow.teacher.presenter.homePage;

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.HomePageSheetMusicListBean;
import com.cooleshow.teacher.bean.QuerySubjectBean;
import com.cooleshow.teacher.bean.TeacherSelfStyleInfoBean;
import com.cooleshow.teacher.bean.request.SheetMusicEntry;
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;

import java.util.List;

/**
 * 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, String idAndName, String subjectIds) {
        if (isShowLoading && getView() != null) {
            getView().showLoading();
        }
        SheetMusicEntry entry = new SheetMusicEntry();
        entry.idAndName = idAndName;
        if(!TextUtils.equals(subjectIds,"0")){
            //全部声部的时候不传这个字段
            entry.subjectIds = subjectIds;
        }
        entry.auditStatus = SHEET_MUSIC_STATUS_PASS;
        entry.page = page;
        entry.rows = Constants.DEFAULT_DATA_SIZE;
        addSubscribe(create(APIService.class).getSheetMusicList(entry), 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);
                }
            }
        });
    }

    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);

            }
        });
    }
}
