package com.device.comm.mylibrary.NativeDevice;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;

import com.device.comm.mylibrary.BleDevice;
import com.device.comm.mylibrary.BleDeviceManager;
import com.device.comm.mylibrary.ENDeviceConst;
import com.device.comm.mylibrary.UpdateLoop;

/**
 * Created by lvwang2002 on 16/1/25.
 */
public class BleNativeDevice {
    public static final String PREPARE = "PREPARE";
    public static final String CREATING_CHANNEL = "CREATING_CHANNEL";
    public static final String CREATED_CHANNEL = "CREATED_CHANNEL";
    public static final String START_AUTHORIZATION = "START_AUTHORIZATION";
    public static final String AUTHORIZATION_SUCCESSFUL = "AUTHORIZATION_SUCCESSFUL";
    public static final String AUTHORIZATION_FAILED = "AUTHORIZATION_FAILED";

    protected String connectedStatus = PREPARE;
    protected UpdateLoop mUpdateLoop;
    protected String mDeviceType;


    public BleNativeDevice(){

    }

    public interface BleNativeDeviceCallback {

    }

    //获得需要检查的服务的udid
    public String getDeviceServiceUUID(){
        return "";
    }

    //获得需要订阅属性的udid
    public  String getNotifyCharacteristicUUID(){
        return "";
    }


    //获取工作的服务和属性
    public void onServicesDiscovered_mainThread(final BluetoothGatt gatt, final int gattStatus) {

    }

    public void receiveData(BluetoothGattCharacteristic characteristic){

    }

    public void setIsGetWriteDescription(BluetoothGatt gatt,boolean flag){
    }

    /** 设置原生的 */
    public void  setNativeDeviceCallback(BleNativeDeviceCallback deviceCallback){

    }

    static public BleNativeDevice getNativeDevice(String name, BleDevice device, BleDeviceManager deviceManager){
        if(name.startsWith("BLE-")){
            return new BleNativeEnuoGlucoseDevice(device, deviceManager);
        }else if(name.startsWith("ClinkBlood")){
            return new BleNativeEnuoBPDevice(device, deviceManager);
        }else if(name.startsWith("iGate")){
            return new BleNativeCholesterolDevice(device,deviceManager);
        }else if(name.startsWith("Glucose")){
            return new BleNativeHMDGlucoseDevice(device,deviceManager);
        }else if(name.startsWith("HbA1c")){
            return new BleNativeBioHermesDevice(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_DYNAMIC_GLUCOSE)){
            return new BleDynamicGlucose(device,deviceManager);
        }else if(name.startsWith((ENDeviceConst.DEVICE_TYPE_G_GLUCOSE))){
            return new BleNativeEnuoGGlucoseDevice(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_DG_TYPE_2)){
            return new BleDGType2Device(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_BIOLAND_GLUCOSE)){
            return new BleNativeBioLandGlucoseDevice(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_BENE_CHECKER)){
            return new BleNativeBeneCheckerDevice(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_DY_BP)){
            return new BleNativeEnuoBPDevice(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_YASEE_BP)){
            return new BleNativeYASEEBPDevice(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_ACCU_CHEK)){
            return new BleNativeAccuGlucoseDevice(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_MQ_DY_GLUCOSE)){
            return new BleMQDynamicGlucose(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_TD_GLUCOSE)){
            return new BleNativeEnuoTDGlucoseDevice(device,deviceManager);
        }else if(name.startsWith(ENDeviceConst.DEVICE_TYPE_YASEE_JN163_BP)){
            return new BleNativeYASEE163EBBPDevice(device,deviceManager);
        }

        return new BleNativeEnuoGlucoseDevice(device,deviceManager);
    }

    public static String Bytes2HexString(byte[] b, int start, int len) {
        String ret = "";
        for (int i = start; i < len; i++) {
            String hex = Integer.toHexString(b[i] & 0xFF);
            if (hex.length() == 1) {
                hex = '0' + hex;
            }
            ret += hex.toUpperCase()+" ";
        }
        return ret;
    }
    public synchronized void postDelay(Runnable runnable,long delayMillis){
        mUpdateLoop.postDelay(runnable,delayMillis);
    }
    public String getDeviceType(){
        return "";
    }
    public String getDeviceDisplayName(){
       // return "怡诺医疗设备";
        return "蚂蚁医疗设备";
    }
    public String getConnectedStatus(){return  PREPARE;}

    public boolean disableNotifications() {
        return true;
    }
}
