package com.common.im.presenter;

import com.common.im.api.IMApi;
import com.common.im.contract.ImAppealContract;
import com.common.im.contract.NoticeContract;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;

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

/**
 * 创建日期：2022/6/13 13:55
 *
 * @author Ryan
 * 类说明：
 */
public class ImAppealPresenter extends BasePresenter<ImAppealContract.ImAppealView> implements NoticeContract.Presenter {

    public void sysImComplaint(String memo, String targetId,String type, String url) {
        if (getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("memo", memo);
            jsonObject.putOpt("targetId", targetId);
            jsonObject.putOpt("type", type);
            jsonObject.putOpt("url", url);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(IMApi.class).sysImComplaint(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object data) {
                if (getView() != null) {
                    getView().sysImComplaintSuccess();
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                if (getView() != null) {
                    getView().hideLoading();
                }
            }
        });
    }
}
