package com.cooleshow.base.presenter;

import android.icu.util.ULocale;

import com.cooleshow.base.bean.request.EditAddressEntry;
import com.cooleshow.base.constanst.EditAddressContract;
import com.cooleshow.base.data.api.UploadApi;
import com.cooleshow.base.data.net.ApiException;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.ErrorParse;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.base.utils.ToastUtil;

/**
 * 创建日期：2022/5/18 10:20
 *
 * @author Ryan
 * 类说明：
 */
public class EditAddressPresenter extends BasePresenter<EditAddressContract.EditAddressView> implements EditAddressContract.Presenter {

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

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

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

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

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

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

}
