package com.demo.mylibrary.api;

import android.util.Log;

import com.demo.mylibrary.api.RequestManager;
import com.demo.mylibrary.bean.APPInfo;
import com.demo.mylibrary.bean.BehaviorInfo;
import com.demo.mylibrary.bean.OutInfo;
import com.demo.mylibrary.bean.PageInfo;

import java.util.List;

import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class PostHelper {
    private static final String TAG = "TAnalytics";

    /**
     * 上传APP信息
     *
     * @param appInfo
     */
    public static void postAppInfo(APPInfo appInfo) {
        RequestManager.getInstance().mApiService
                .postAppInfo(appInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .subscribe(new Consumer<OutInfo>() {
                    @Override
                    public void accept(OutInfo outInfo) throws Exception {
                        if (outInfo.getStatus() == 200) {
                            Log.d(TAG, outInfo.getMessage());
                        }
                    }
                });
    }

    /**
     * 上传单个PageInfo--WIFI
     *
     * @param page
     */
    public static void postPage(PageInfo page) {
        RequestManager.getInstance().mApiService
                .postPageInfo(page)
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .subscribe(new Consumer<OutInfo>() {
                    @Override
                    public void accept(OutInfo outInfo) throws Exception {
                        if (outInfo.getStatus() == 200) {
                            Log.d(TAG, outInfo.getMessage());
                        }
                    }
                });
    }

    /**
     * 上传PageInfoList--MOBILE
     *
     * @param pageList
     */
    public static void postPgaeList(List<PageInfo> pageList) {
        RequestManager.getInstance().mApiService
                .postPageList(pageList)
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .subscribe(new Consumer<OutInfo>() {
                    @Override
                    public void accept(OutInfo outInfo) throws Exception {
                        if (outInfo.getStatus() == 200) {
                            Log.d(TAG, outInfo.getMessage());
                        }
                    }
                });
    }

    /**
     * 上传单个BehaviorInfo--WIFI
     * @param behaviorInfo
     */
    public static void postBehavior(BehaviorInfo behaviorInfo){
        RequestManager.getInstance().mApiService
                .postBehavior(behaviorInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .subscribe(new Consumer<OutInfo>() {
                    @Override
                    public void accept(OutInfo outInfo) throws Exception {
                        if (outInfo.getStatus() == 200) {
                            Log.d(TAG, outInfo.getMessage());
                        }
                    }
                });
    }

    /**
     * 上传BehaviorInfoList--MOBILE
     * @param behaviorList
     */
    public static void postBehaviorList(List<BehaviorInfo> behaviorList) {
        RequestManager.getInstance().mApiService
                .postBehaviorList(behaviorList)
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .subscribe(new Consumer<OutInfo>() {
                    @Override
                    public void accept(OutInfo outInfo) throws Exception {
                        if (outInfo.getStatus() == 200) {
                            Log.d(TAG, outInfo.getMessage());
                        }
                    }
                });
    }
}
