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

import com.casic.dcms.bean.CaseListResultBean;
import com.casic.dcms.listener.OnGetSearchListListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.CaseListModelImpl;
import com.casic.dcms.mvp.presenter.ICaseListPresenter;
import com.casic.dcms.mvp.view.ICaseListView;

public class CaseListPresenterImpl extends BasePresenter implements ICaseListPresenter, OnGetSearchListListener {

    private final ICaseListView view;
    private final CaseListModelImpl actionModel;

    public CaseListPresenterImpl(ICaseListView caseListView) {
        this.view = caseListView;
        actionModel = new CaseListModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String eorc, String casetypeCode, String casetypeDetailCode,
                                       String caseState, String registerTimeBegin, String registerTimeEnd,
                                       String isShopCase, int offset) {
        view.showProgress();
        addSubscription(actionModel.sendCaseListRequest(eorc, casetypeCode, casetypeDetailCode, caseState,
                registerTimeBegin, registerTimeEnd, isShopCase, offset));
    }

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

    @Override
    public void onSuccess(CaseListResultBean resultBean) {
        view.hideProgress();
        view.obtainCaseListData(resultBean);
    }

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