package zd.common.mqtt.config;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotBlank;
import java.util.UUID;

/**
 * @Author: zhoupan
 * @Date: 2021/11/15/14:27
 * @Description:
 */
@ConfigurationProperties("sys.mqtt")
@Validated
public class MqttProperties {

    /**
     * 账号
     */
    private String username="";

    /**
     * 密码
     */
    private String password="";

    /**
     * mqtt服务地址 多个用”,“分割
     */
    @NotBlank(message = "mqtt服务地址不能为空")
    private String url;

    private String defaultTopic="mqtt_defaultTopic";

    /**
     * 客户端ID
     */
    private String producerClientId;

    /**
     * 消费者客户端ID
     */
    private String consumerClientId;

    /**
     * 订阅主题
     */
    private String topics="";


    public String getTopics() {
        return topics;
    }

    public void setTopics(String topics) {
        this.topics = topics;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getDefaultTopic() {
        return defaultTopic;
    }

    public void setDefaultTopic(String defaultTopic) {
        this.defaultTopic = defaultTopic;
    }

    public String getProducerClientId() {
        if(!StringUtils.hasLength(producerClientId)) return UUID.randomUUID().toString();
        return producerClientId;
    }

    public void setProducerClientId(String producerClientId) {
        this.producerClientId = producerClientId;
    }

    public String getConsumerClientId() {
        if(!StringUtils.hasLength(consumerClientId)) return UUID.randomUUID().toString();
        return consumerClientId;
    }

    public void setConsumerClientId(String consumerClientId) {
        this.consumerClientId = consumerClientId;
    }
}
