package com.zj365.dc.model

import com.lifesense.android.ble.core.application.BleDeviceManager
import com.lifesense.android.ble.core.application.model.enums.ConnectionState
import com.lifesense.android.ble.core.valueobject.DeviceInfo
import com.zj365.health.act.binddevice.BlueUtil

class DeviceStateWrapper {

    protected var device: DeviceInfo? = null
    constructor() {}

    constructor(device: DeviceInfo?, state: ConnectionState?){
        this.device = device
        this.state = state
    }

    fun getDeviceId(): String? {
        return if (device != null) {
            device!!.mac
        } else null
    }

    private var state: ConnectionState? = null

    fun getMyDevice(): DeviceInfo? {
        return device
    }

    fun setMyDevice(device: DeviceInfo?) {
        this.device = device
    }

    fun getState(): ConnectionState? {
        return state
    }

    fun setState(state: ConnectionState?) {
        this.state = state
    }

    fun isConnected(): Boolean {
        return state != null && state == ConnectionState.CONNECTED
    }

    fun checkDeviceConnectState(): Boolean {
        if (device != null) {
            state = BlueUtil.getBlueManage().getDeviceConnectState(device!!.mac)
        }
        return isConnected()
    }
}