package cn.iododer.yudao.module.mqtt.config;

import cn.hutool.core.util.IdUtil;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * Mqtt Config
 *  *     备注：以下刻意将 defaultClientId、clientId 区分使用。
 *  *          防止断线重连的时候，clientId 被重复拼接时间戳
 */
@Getter
@Configuration
public class MqttProperties {

    @Value("${mqtt.host}")
    private String hostUrl;

    @Value("${mqtt.username}")
    private String username;

    @Value("${mqtt.password}")
    private String password;

    @Value("${mqtt.clientId}")
    private String clientId;

    @Value("${mqtt.qos}")
    private int qos;

    @Value("${mqtt.maxInflight}")
    private int maxInflight;

    private String clientUUId;

    public String getClientId() {
        if (clientUUId == null) {
            clientUUId = clientId + IdUtil.fastSimpleUUID();
        }
        return clientUUId;
    }
}
