package com.casic.dcms.mvp.presenter;

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.CaseHandleModelImpl;
import com.casic.dcms.mvp.view.ICaseHandleView;

/**
 * @Author: Pengxh
 * @Time: 2021/4/12 13:29
 * @Email: 290677893@qq.com
 **/
public class CaseHandlePresenterImpl extends BasePresenter implements ICaseHandlePresenter, CaseHandleModelImpl.OnHandleListener {

    private ICaseHandleView view;
    private CaseHandleModelImpl actionModel;

    public CaseHandlePresenterImpl(ICaseHandleView caseHandleView) {
        this.view = caseHandleView;
        actionModel = new CaseHandleModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String processId, String bizId, String currState, String changeState,
                                       String remarks, String fileId) {
        view.showProgress();
        addSubscription(actionModel.sendRetrofitRequest(processId, bizId, currState, changeState, remarks, fileId));
    }

    @Override
    public void onReadyRetrofitRequest(String processId, String bizId, String currState, String changeState,
                                       String remarks, String fileId, String approvalResult) {
        view.showProgress();
        addSubscription(actionModel.sendRetrofitRequest(processId, bizId, currState, changeState, remarks, fileId,
                approvalResult));
    }

    @Override
    public void onReadyRetrofitRequest(String processId, String bizId, String currState, String changeState,
                                       String remarks, String fileId, String eorc, String casetypeCode,
                                       String casetypeDetailCode, String lng, String lat, String caseLevel,
                                       String areaCode, String streetCode, String communityCode, String gridId,
                                       String fieldintro) {
        view.showProgress();
        addSubscription(actionModel.sendRetrofitRequest(processId, bizId, currState, changeState,
                remarks, fileId, eorc, casetypeCode, casetypeDetailCode, lng, lat, caseLevel, areaCode,
                streetCode, communityCode, gridId, fieldintro));
    }

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

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

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