package org.dromara.app.handler;

import lombok.extern.slf4j.Slf4j;
import org.dromara.app.mqtt.MqttTopicHandler;
import org.dromara.app.service.IDeviceCommandAckHandler;
import org.springframework.stereotype.Component;

import java.util.regex.Pattern;

/**
 * 设备命令 ACK 处理器 — 匹配 /{deviceNo}/publish/ack。
 * 委托给 {@link IDeviceCommandAckHandler}（实际由 water-common-mqtt 模块的 MqttCommandAckService 实现）。
 */
@Slf4j
@Component
public class DeviceCommandAckHandler implements MqttTopicHandler {

    private static final Pattern PATTERN = Pattern.compile("^/([^/]+)/publish/ack$");

    private final IDeviceCommandAckHandler delegate;

    public DeviceCommandAckHandler(IDeviceCommandAckHandler delegate) {
        this.delegate = delegate;
    }

    @Override
    public Pattern topicPattern() {
        return PATTERN;
    }

    @Override
    public void handle(String deviceNo, String payload) {
        delegate.handleAck(deviceNo, payload);
    }
}
