package com.cooleshow.teacher.presenter.homework;

import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.bean.HomeworkListBean;
import com.cooleshow.teacher.bean.SparringCourseHomeworkBean;
import com.cooleshow.teacher.bean.request.AssignHomeWorkEntry;
import com.cooleshow.teacher.bean.request.CommentHomeWorkEntry;
import com.cooleshow.teacher.constants.AssignHomeworkContract;

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

/**
 * 创建日期：2022/5/31 15:48
 *
 * @author Ryan
 * 类说明：
 */
public class AssignHomeworkPresenter extends BasePresenter<AssignHomeworkContract.AssignHomeworkView> implements AssignHomeworkContract.Presenter {

    public void getCourseDetail(String courseId, String studentId) {
        if (getView() != null) {
            getView().showLoading();
        }
        addSubscribe(create(APIService.class).getSparringCourseHomework(courseId, studentId), new BaseObserver<SparringCourseHomeworkBean>(getView()) {
            @Override
            protected void onSuccess(SparringCourseHomeworkBean data) {
                if (getView() != null) {
                    getView().getSparringCourseHomework(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                getView().hideLoading();
            }

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

    public void submitSparringCourseHomework(String content, String courseId) {
        if (getView() != null) {
            getView().showLoading();
        }
        AssignHomeWorkEntry entry = new AssignHomeWorkEntry();
        entry.courseScheduleId = courseId;
        entry.content = content;
        entry.attachments = content;

        addSubscribe(create(APIService.class).submitSparringCourseHomework(entry), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object o) {
                if (getView() != null) {
                    getView().submitSparringCourseHomeworkSuccess();
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        });
    }
    public void submitSparringCourseHomeworkComment(String commentContent, String courseScheduleId,String studentId ) {
        if (getView() != null) {
            getView().showLoading();
        }
        CommentHomeWorkEntry entry = new CommentHomeWorkEntry();
        entry.courseScheduleId = courseScheduleId;
        entry.review = commentContent;
        entry.studentId = studentId;
        addSubscribe(create(APIService.class).submitSparringCourseHomeworkComment(entry), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object o) {
                if (getView() != null) {
                    getView().submitSparringCourseHomeworkCommentSuccess();
                }
            }

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