package com.cooleshow.base.presenter;

import android.content.res.ObbInfo;

import com.cooleshow.base.bean.AddressBean;
import com.cooleshow.base.constanst.AddressListContract;
import com.cooleshow.base.data.api.UploadApi;
import com.cooleshow.base.data.net.ApiException;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.base.utils.ErrorParse;

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(UploadApi.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();
                if (getView() != null) {
                    getView().hideLoading();
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        });
    }

    public void delAddress(int id) {
        getView().showLoading();
        addSubscribe(create(UploadApi.class).delAddress(id), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object data) {
                if (getView() != null) {
                    getView().delAddress();
                }
            }

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