package com.cooleshow.student.presenter.course;

import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.student.api.APIService;
import com.cooleshow.student.contract.EvaluateTeacherContract;

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

/**
 * 创建日期：2022/5/31 11:26
 *
 * @author Ryan
 * 类说明：
 */
public class EvaluateTeacherPresenter extends BasePresenter<EvaluateTeacherContract.EvaluateTeacherView> implements EvaluateTeacherContract.Presenter {
    /**
     * 提交陪练课老师评价
     *
     * @param commentContent
     * @param courseScheduleId
     * @param courseGroupId
     */
    public void submitSparringCourseComment(String commentContent, String courseScheduleId, String courseGroupId,float score) {
        if (getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("courseScheduleId", courseScheduleId);
            jsonObject.putOpt("studentReplied", commentContent);
            jsonObject.putOpt("courseGroupId", courseGroupId);
            jsonObject.putOpt("score", score);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        addSubscribe(create(APIService.class).submitSparringCourseComment(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object o) {
                if (getView() != null) {
                    getView().submitSparringCourseTeacherCommentSuccess();
                }
            }

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