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

import com.casic.dcms.bean.CaseHandleBean;
import com.casic.dcms.listener.OnGetCaseHandleListListener;
import com.casic.dcms.mvp.model.ICaseHandleListModel;
import com.casic.dcms.utils.retrofit.RetrofitServiceManager;

import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class CaseHandleListModelImpl implements ICaseHandleListModel {

    private final OnGetCaseHandleListListener caseHandleListListener;

    public CaseHandleListModelImpl(OnGetCaseHandleListListener listener) {
        this.caseHandleListListener = listener;
    }

    /**
     * {@link ICaseHandleListModel}
     * <p>
     * 案卷处理-超时案卷/紧急案卷/待办案卷列表
     * 地图查看案卷-处置中
     */
    @Override
    public Subscription sendCaseHandleListRequest(String isOvertime, String isEmergent, int limit, int offset) {
        Observable<CaseHandleBean> observable = RetrofitServiceManager.getCaseHandleListResult(isOvertime,
                isEmergent, limit, offset);
        return observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<CaseHandleBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                if (e.getCause() != null) {
                    caseHandleListListener.onFailure(e);
                }
            }

            @Override
            public void onNext(CaseHandleBean resultBean) {
                if (resultBean != null) {
                    caseHandleListListener.onSuccess(resultBean);
                }
            }
        });
    }
}
