package com.common.im.presenter;

import com.common.im.api.IMApi;
import com.common.im.contract.NoticeContract;
import com.common.im.contract.SetRemarksContract;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.usercenter.helper.UserHelper;

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

/**
 * 创建日期：2022/6/13 11:18
 *
 * @author Ryan
 * 类说明：
 */
public class SetRemarksPresenter extends BasePresenter<SetRemarksContract.SetRemarksView> implements SetRemarksContract.Presenter {


    public void updateGroupInfo(String groupId,String name){
        if (getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("name", name);
            jsonObject.putOpt("id", groupId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(IMApi.class).updateGroupInfo(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object data) {
                if (getView() != null) {
                    getView().updateGroupInfoSuccess(groupId, name);
                }
            }

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