package com.casic.dcms.mvp.model;

import com.casic.dcms.bean.OvertimeCaseBean;
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 OvertimeCaseListModelImpl implements IOvertimeCaseListModel {

    private OnGetOvertimeCaseListListener listener;

    public OvertimeCaseListModelImpl(OnGetOvertimeCaseListListener overtimeCaseListListener) {
        this.listener = overtimeCaseListListener;
    }

    public interface OnGetOvertimeCaseListListener {
        void onSuccess(OvertimeCaseBean resultBean);

        void onFailure(Throwable throwable);
    }

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

            }

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

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