package com.casic.dcms.mvp.model;

import com.casic.dcms.bean.CaseVerifiedBean;
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 CaseVerifiedModelImpl implements ICaseVerifiedModel {

    private OnGetCaseVerifiedListener listener;

    public CaseVerifiedModelImpl(OnGetCaseVerifiedListener caseVerifiedListener) {
        this.listener = caseVerifiedListener;
    }

    public interface OnGetCaseVerifiedListener {
        void onSuccess(CaseVerifiedBean resultBean);

        void onFailure(Throwable throwable);
    }

    @Override
    public Subscription sendRetrofitRequest(int offset) {
        Observable<CaseVerifiedBean> observable = RetrofitServiceManager.getCaseVerifiedListResult(offset);
        return observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<CaseVerifiedBean>() {
            @Override
            public void onCompleted() {

            }

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

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