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.SubmitMaintainModelImpl;
import com.casic.dcms.mvp.presenter.ISubmitMaintainPresenter;
import com.casic.dcms.mvp.view.IMaintainSubmitView;

public class SubmitMaintainPresenterImpl extends BasePresenter implements ISubmitMaintainPresenter,
        OnActionResultListener {

    private final IMaintainSubmitView view;
    private final SubmitMaintainModelImpl actionModel;

    public SubmitMaintainPresenterImpl(IMaintainSubmitView submitCaseView) {
        this.view = submitCaseView;
        actionModel = new SubmitMaintainModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String bridgeId, String content, String maintainTime, String personId,
                                       String longitude, String latitude, String description) {
        view.showProgress();
        addSubscription(actionModel.sendMaintainSubmitRequest(bridgeId, content, maintainTime, personId, longitude,
                latitude, description));
    }

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

    @Override
    public void onFailure(Throwable throwable) {
        view.hideProgress();
        view.obtainDataFail();
    }

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