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

import com.casic.dcms.bean.CaseHandledBean;
import com.casic.dcms.listener.OnGetCaseHandledListListener;
import com.casic.dcms.mvp.model.ICaseHandledListModel;
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 CaseHandledListModelImpl implements ICaseHandledListModel {

    private final OnGetCaseHandledListListener caseHandledListListener;

    public CaseHandledListModelImpl(OnGetCaseHandledListListener listener) {
        this.caseHandledListListener = listener;
    }

    /**
     * {@link ICaseHandledListModel}
     * <p>
     * 案卷处理-已办案卷列表
     */
    @Override
    public Subscription sendCaseHandledListRequest(int offset) {
        Observable<CaseHandledBean> observable = RetrofitServiceManager.getCaseHandledListResult(offset);
        return observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<CaseHandledBean>() {
            @Override
            public void onCompleted() {

            }

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

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