package com.tofly.ghrq_route.module.systemConfig.controller;

import android.content.Context;

import com.tofly.ghrq_route.module.OfflineWork.OfflineWorkTool;
import com.tofly.ghrq_route.module.systemConfig.domain.ServerSysConfigBean;
import com.tofly.ghrq_route.module.systemConfig.service.IServerSysConfigService;
import com.tofly.ghrq_route.module.systemConfig.service.ServerSysConfigServiceImpl;
import com.tofly.ghrq_route.module.systemConfig.service.ServerSysConfigServiceImplOffline;

import java.util.List;

/**
 * Created by Amu on 2017/8/8.
 */

public class ServerSysConfigController {

    /**
     * 是否在綫
     */
    boolean mbOnline;
    /**
     * 上下文
     */
    Context mContext;
    /**
     * 接口实现对象
     */
    IServerSysConfigService sysConfigService;

    public ServerSysConfigController(Context context){
        mbOnline = true;
        mContext = context;
        sysConfigService = new ServerSysConfigServiceImpl(context);
    }

    public ServerSysConfigController(boolean online, Context context){
        mbOnline = online;
        mContext = context;
        sysConfigService = new ServerSysConfigServiceImpl(context);
    }

    private void setSignService(){
        boolean isOffline = OfflineWorkTool.isOffline();
        if (isOffline){
            sysConfigService = new ServerSysConfigServiceImplOffline(mContext);
        }else {
            sysConfigService = new ServerSysConfigServiceImpl(mContext);
        }
    }

    /**
     * 获取隐患设备类型信息
     * @param token
     * @param pageindex 当前页index
     * @param pagesize  每页数据大小
     * @param sysConfigCallBack
     */
    public void getSysConfigList(String token, String key, int pageindex, int pagesize,
                               final ServerSysConfigCallBack sysConfigCallBack){
        setSignService();
        sysConfigService.getSysConfigList(token, key, pageindex, pagesize, sysConfigCallBack);
    }

    public void getPhotoTypeConfigList(String token, int pageindex, int pagesize,
                                       final ServerSysConfigCallBack sysConfigCallBack){
        setSignService();
        sysConfigService.getSysConfigList(token, ServerSysConfigBean.SYS_CONFIG_PHOTO_TYPE, pageindex, pagesize, sysConfigCallBack);
    }

    /**
     *  获取服务器设置参数列表
     */
    public void getSysSetting(Context context, final ServerSysConfigCallBack sysConfigCallBack){
        sysConfigService = new ServerSysConfigServiceImpl(mContext);
        sysConfigService.getSysSetting(context, sysConfigCallBack);
    }

    /**
     *  上传本地日志（包括本地巡检点.txt， 日志记录文件.txt, 奔溃日志.txt）到服务器
     */
    public void uploadLocalSystemLogFiles(Context context, List<String> files, final ServerSysConfigCallBack sysConfigCallBack){
        sysConfigService = new ServerSysConfigServiceImpl(mContext);
        sysConfigService.uploadLocalSystemLogFiles(context, files, sysConfigCallBack);
    }
}
