package com.quyunshuo.module.home.receiver

import android.content.Context
import com.google.gson.Gson

import com.module.pay.service.HomeApiService

import com.quyunshuo.androidbaseframemvvm.common.constant.Heartbeat
import com.quyunshuo.module.home.service.ManageMqtt
import javax.inject.Inject
import javax.inject.Singleton

/**
 * 对Mqtt操作的进一步封装
 */
@Singleton
class MqttHelper @Inject constructor() {

    @Inject
    lateinit var mqtt: ManageMqtt


    /**
     * 注册
     */
    fun register(context: Context?) {
        mqtt.init(context)

    }

    fun isMqConnected(): Boolean {
        return mqtt.isMqConnected
    }

    /**
     * 发送数据
     */
    fun sendData(topic: String, data: String) {
        //{"kindData:1","kindId:openDev"}
        if ("" != (Heartbeat.deviceId)) {
            if (mqtt != null && mqtt.isMqConnected) {
                Heartbeat.deviceId?.let { mqtt.publish(topic, data) }

            }
        }

    }

    /**
     * 接收数据
     */
    fun data(kind: String, data: String) {
        //待定，一般都是通过eventbus来解决。
    }
}