package org.dromara.mqtt.config.properties;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.List;

@Data
//@Component
@ConfigurationProperties(prefix = "mqtt")
public class MqttProperties {

    private boolean enabled = false;
    private String brokerUrl;
    private String username;
    private String password;
    private String clientId;
    private int qos = 1;
    private int keepAlive = 300;
    private int connectionTimeout = 30;
    private int maxInflight = 1000;
    private boolean cleanSession = false;
    private boolean automaticReconnect = true;
    private Topics topics = new Topics();
    private Async async = new Async();
    private Tls tls = new Tls();
    private CommandAck commandAck = new CommandAck();

    @Data
    public static class Topics {
        private List<String> subscribe = new ArrayList<>();
        private String publishPrefix;
    }

    @Data
    public static class Async {
        private int corePoolSize = 8;
        private int maxPoolSize = 32;
        private int consumerCount = 16;
        private int queueCapacity = 5000;
        private int batchSize = 100;
        private long offerTimeoutMs = 50;
        private long pollTimeoutMs = 100;
    }

    @Data
    public static class Tls {
        private boolean enabled = true;
        private boolean skipVerify = false;
    }

    @Data
    public static class CommandAck {
        private boolean enabled = true;
        private int maxRetryCount = 3;
        private long retryIntervalMs = 10000;
        private long scanIntervalMs = 5000;
        private long pendingTtlSeconds = 86400;
        private long ackTtlSeconds = 86400;
        private String pendingKeyPrefix = "mqtt:command:pending:";
        private String ackKeyPrefix = "mqtt:command:ack:";
        private String pendingSetKey = "mqtt:command:pending:ids";
        private String retryLockKeyPrefix = "lock:mqtt:command:retry:";
        private long retryLockTtlMs = 30000;
        private long ackLockWaitMs = 3000;
        private String deviceStatusCachePrefix = "mqtt:device:status:";
        private long deviceStatusCacheTtlSeconds = 900;
    }

}
