package com.casic.dcms.mvp.presenter.impl;

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.listener.OnActionResultListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.UploadPositionModelImpl;
import com.casic.dcms.mvp.presenter.IUploadPositionPresenter;
import com.casic.dcms.mvp.view.IUploadPositionView;

public class UploadPositionPresenterImpl extends BasePresenter implements IUploadPositionPresenter,
        OnActionResultListener {

    private final IUploadPositionView view;
    private final UploadPositionModelImpl actionModel;

    public UploadPositionPresenterImpl(IUploadPositionView uploadPositionView) {
        this.view = uploadPositionView;
        actionModel = new UploadPositionModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String imei, String positionLat, String positionLng) {
        addSubscription(actionModel.sendUploadPositionRequest(imei, positionLat, positionLng));
    }

    @Override
    public void onSuccess(ActionResultBean resultBean) {
        view.obtainUploadPositionResult(resultBean);
    }

    @Override
    public void onFailure(Throwable throwable) {

    }

    @Override
    public void disposeRetrofitRequest() {
        unSubscription();
    }
}
