package com.cooleshow.teacher.presenter.live;

import com.cooleshow.base.data.net.ApiException;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.ErrorParse;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.contract.CreateLiveContract;

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

/**
 * 创建日期：2022/5/20 15:01
 *
 * @author Ryan
 * 类说明：
 */
public class CreateLivePresenter extends BasePresenter<CreateLiveContract.CreateLiveView> implements CreateLiveContract.Presenter {


    /**
     * 创建临时直播间
     *
     * @param liveRemark
     * @param roomTitle
     */
    @Override
    public void createTempLive(String liveRemark, String roomTitle,String liveDuration) {
        getView().showLoading();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("liveRemark", liveRemark);
            jsonObject.putOpt("roomTitle", roomTitle);
            jsonObject.putOpt("liveTime", liveDuration);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).createLiveRoom(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<String>(getView()) {
            @Override
            protected void onSuccess(String data) {
                if (getView() != null) {
                    getView().onCreateLiveSuccess(data);
                }
            }

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

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