package com.cooleshow.student.presenter.mine;

import com.cooleshow.base.data.net.ApiException;
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.base.utils.ToastUtils;
import com.cooleshow.base.utils.ErrorParse;
import com.cooleshow.student.api.APIService;
import com.cooleshow.student.contract.FeedBackContract;

import java.util.Map;

/**
 * 创建日期：2022/5/18 16:26
 *
 * @author Ryan
 * 类说明：
 */
public class FeedBackPresenter extends BasePresenter<FeedBackContract.FeedBackView> implements FeedBackContract.Presenter {
    public void addSuggestion(Map<String, String> params) {
        getView().showLoading();
        addSubscribe(create(APIService.class).addSuggestion(params), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object data) {
                if (getView() != null) {
                    getView().addSuggestionSuccess(data);
                }
            }

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

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if (e instanceof ApiException) {
                    ErrorParse.getInstance().parseError(e);
                    ApiException apiException = (ApiException) e;
                    ToastUtil.getInstance().showShort(apiException.getErrmsg());
                }
            }
        });
    }

}
