package com.oo.eye.net;

import android.content.Context;

import com.app.baselibrary.base.app.BaseApplication;
import com.app.baselibrary.bean.UserInfo;
import com.oo.eye.bean.EyeChartsBean;
import com.oo.eye.bean.EyeHistroyBean;
import com.oo.eye.bean.InitDataBean;
import com.oo.seex.netlibrary.net.response.NewResponseImpl;

import java.util.ArrayList;

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

/**
 * Desc:app管理类；（网络本地管理）
 * Author: pl
 * Date: 2017-03-16 19:45
 */

public class EyeDataManager {
    private static final String TAG = "EyeDataManager";
    private static EyeDataManager sAppDateManager;
    private Context mContext;
    public static EyeDataManager getInstance() {
        if (null == sAppDateManager) {
            synchronized (EyeDataManager.class) {
                if (null == sAppDateManager)
                    sAppDateManager = new EyeDataManager();
            }
        }
        return sAppDateManager;
    }
    public EyeDataManager() {
        mContext = BaseApplication.getAppContext();
    }


    /**
     * 上传视力测试结果
     */
    public Observable<NewResponseImpl<String>> postEyeTestData(String deviceSn, String leftEye, String rightEye, String leftLine, String rightLine) {
        return EyeNetManager.getInstance().getApiService(EyeApiService.class).postEyeTestData(deviceSn,leftEye,rightEye,leftLine,rightLine).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
    /**
     * 获取用户信息
     */
    public Observable<NewResponseImpl<UserInfo>> getUserInfo(String deviceSN) {
        return EyeNetManager.getInstance().getApiService(EyeApiService.class).getUserInfo(deviceSN).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
    /**
     * 获取初始数据
     */
    public Observable<NewResponseImpl<InitDataBean>> getEyeInit(String deviceSn) {
        return EyeNetManager.getInstance().getApiService(EyeApiService.class).getEyeInit(deviceSn).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
    /**
     *获取视力测试历史结果
     * @return
     */
    public Observable<NewResponseImpl<ArrayList<EyeHistroyBean>>>getEyeTestData(String deviceSn, int page, int limit) {
        return EyeNetManager.getInstance().getApiService(EyeApiService.class).getEyeTestData(deviceSn,page,limit).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
    /**
     * 获取视力测试历史结果
     */
    public Observable<NewResponseImpl<ArrayList<EyeChartsBean>>> getEyeTestCharts(String deviceSn, int limit) {
        return EyeNetManager.getInstance().getApiService(EyeApiService.class).getEyeTestCharts(deviceSn,limit).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }


}
