var MethodModule = require('react-native').NativeModules.RNMethodModule;
const RechoMethodModule = require('react-native').NativeModules.RNRocheModule;
const MQModule = require('react-native').NativeModules.RNMQModule;

import RNDYGlucoseDriver from './rn-dy-glucose-driver';
import RNADIDDriver from './rn-adid-driver';
export const DYGlucoseDriver = RNDYGlucoseDriver.shareDriver();
export const ADIDDriver = RNADIDDriver.shareDriver();
export default class RNMethodModule{
    static startScanDevice(){
        MethodModule.startScanDevice();
    }

    /** 停止扫描所有设备  */
    static stopScanDevice(){
        MethodModule.stopScanDevice();
    }

    /** 开始扫描尿酸 */
    static startScanACID(){
        MethodModule.startScanACID();
    }

    /** 停止扫描尿酸 */
    static stopScanACID(){
        MethodModule.stopScanACID();
    }

    static connectACID(deviceMac){
        MethodModule.connectACID(deviceMac);
    }

    /** 获取当前连接的所有尿酸设备 */
    static getConnectedACID(){
        return new Promise((resolve,reject)=>{
            MethodModule.getConnectedACID()
            .then((deviceList)=>{
                resolve(deviceList);
            },(error)=>{
                reject(error);
            })
        })
    }

    static  startCardReaderScan() {
        return new Promise((resolve, reject) => {
            MethodModule.startCardReaderScan()
            .then((result)=>{
                resolve(result);
            },(error)=>{
                reject(error);
            })
        });
    }

    static  connectCardReader(deviceMac) {
        return new Promise((resolve, reject) => {
            MethodModule.connectCardReader(deviceMac)
            .then((result)=>{
                resolve(result);
            },(error)=>{
                reject(error);
            })
        });
    }

    static  stopCardReaderScan(){
        return new Promise((resolve,reject)=>{
            MethodModule.stopCardReaderScan()
            .then((result)=>{
                resolve(result);
            },(error)=>{
                reject(error);
            });
        });
    }

    static readCard() {
        return new Promise((resolve, reject) => {
            MethodModule.readCard()
            .then((result)=>{
                resolve(result);
            },(error)=>{
                reject(error);
            });
        })
    }

    static startScanGlucose(){
        MethodModule.startScanGlucose();
    }

    static stopScanGlucose(){
        MethodModule.stopScanGlucose();
    }

    /**  开启监控外部设备设备 */
    static startUpdateDeviceList(){
        MethodModule.startUpdateDeviceList();
    }

    /** 关闭外部设备 */
    static stopUpdateDeviceList(){
        MethodModule.stopUpdateDeviceList();
    }

    /** 连接单独设备,连接的同时会断开所有的设备 */
    static connectSingleDevice(deviceMac){
        MethodModule.connectSingleDevice(deviceMac);
    }

    /** 断开指定的设备 */
    static disconnectGlucose(deviceMac){
        MethodModule.disconnectGlucose(deviceMac);
    }

    /** 获取当前连接的所有血糖设备 */
    static getConnectedGlucose(){
        return new Promise((resolve,reject)=>{
            MethodModule.getConnectedGlucose()
            .then((glucoseDevices)=>{
                resolve(glucoseDevices);
            },(error)=>{
                reject(error);
            })
        })
    }

    /** 连接单独的血压设备 */
    static connectSingleBPDevice(deviceMac){
        MethodModule.connectSingleBPDevice(deviceMac);
    }

    /**  */
    static startTestBP(deviceMac){
        MethodModule.startTestBP(deviceMac);
    }
    /** 停止测量血压 */
    static stopTestBP(deviceMac){
        MethodModule.stopTestBP(deviceMac);
    }

    /** 得到血压计电量 */
    static getBPBatteryValue(deviceMac){
        MethodModule.getBPBatteryValue(deviceMac);
    }

    /** 关断设备 */
    static  powerOffDevice(deviceMac){
        MethodModule.powerOffDevice(deviceMac);
    }

    /** 获取当前连接的所有血压设备 */
    static getConnectedBP(){
        return new Promise((resolve,reject)=>{
            MethodModule.getConnectedBP()
            .then((BPDevices)=>{
                resolve(BPDevices);
            },(error)=>{
                reject(error);
            })
        })
    }

    static sendSetDyBP(mac){
        MethodModule.sendSetDyBP(mac);
    }

    /** 强制刷新设备列表 */
    static forceUpdateDeviceList(){
        MethodModule.forceUpdateDeviceList(); 
    }

    /** 断开指定的设备 */
    static disconnectDevice(deviceMac){
        MethodModule.disconnectDevice(deviceMac);
    }
    /** 开始监控厚美德一体机血糖仪 */
    static startMonitT8601MD(){
        MethodModule.startMonitT8601MD()
    }

    /**　设定是否现实日志 */
    static showLog(isShow){
        MethodModule.showLog(isShow);
    }

    static autoConnectAccuChek(mac){
        RechoMethodModule.autoConnectAccuChek(mac);
    }
    static removeAccuListener(){
        RechoMethodModule.removeAccuListener();
    }
    static getBindDeviceList(deviceName) {
        return RechoMethodModule.getBindDeviceList(deviceName);
    }

    static connectMQ(mac){
        MQModule.connectDynamicGlucose(mac)
    };
    static startWorkMQ(mac){
        MQModule.startWork(mac)

    }
    static continueWorkMQ(mac){
        MQModule.continueWork(mac)
    }

    static  glucoseCalculation(index, //包名
        elecValue,  //电量
        lastElecAdjustValue, //上次校准电量
        referenceValue,   //参比血糖系数，10倍传递 0
        referenceGlucoseValue, //参比血糖，10倍传递 0
        bValue
        ){
            return MQModule.glucoseCalculation(index,elecValue,lastElecAdjustValue,referenceValue,referenceGlucoseValue,bValue);
        }

    static disconnectMQDYG(mac){
        MQModule.disconnectMQDYG(mac);
    }
     

        // octor I/ReactNativeJS: 'zll1-----:MQ-didGetMQData', [ { power: 3,
        //     index: 287,
        //     value: 6,
        //     deviceMac: 'D2:3E:16:F4:FA:55',
        //     deviceName: 'O000477' } ]
}