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.ToastUtils;
import com.cooleshow.base.utils.ErrorParse;
import com.cooleshow.student.api.APIService;
import com.cooleshow.student.bean.AddressBean;
import com.cooleshow.student.contract.AddressListContract;

import java.util.List;

/**
 * 创建日期：2022/5/17 15:23
 *
 * @author Ryan
 * 类说明：
 */
public class AddressListPresenter extends BasePresenter<AddressListContract.AddressListView> implements AddressListContract.Presenter {
    public void companyAddressList() {
        getView().showLoading();
        addSubscribe(create(APIService.class).companyAddressList(), new BaseObserver<List<AddressBean>>(getView()) {
            @Override
            protected void onSuccess(List<AddressBean> data) {
                if (getView() != null) {
                    getView().companyAddressListSuccess(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;
                    ToastUtils.showShort(apiException.getErrmsg());
                }
            }
        });
    }
}
