package com.common.im.presenter;

import com.common.im.api.IMApi;
import com.common.im.contract.CreateGroupContract;
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/10 17:39
 *
 * @author Ryan
 * 类说明：
 */
public class CreateGroupPresenter extends BasePresenter<CreateGroupContract.CreateGroupView> implements CreateGroupContract.Presenter {
    public void createGroup(String name,String introduce){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("name", name);
            jsonObject.put("introduce", introduce);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(IMApi.class).createImGroup(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object data) {
                if (getView() != null) {
                    getView().createImGroupSuccess();
                }
            }

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

        });
    }
}
