package de.assecutor.votianlt.messaging.plugin;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * Options for sending messages via plugins.
 * Provides transport-agnostic options with extensibility for plugin-specific settings.
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SendOptions {

    /**
     * Quality of Service level (0, 1, 2 for MQTT-like transports)
     */
    @Builder.Default
    private int qos = 1;

    /**
     * Whether the message should be retained by the broker/server
     */
    @Builder.Default
    private boolean retained = false;

    /**
     * Message priority (if supported by transport)
     */
    @Builder.Default
    private int priority = 0;

    /**
     * Message expiry time in seconds (if supported by transport)
     */
    private Long expirySeconds;

    /**
     * Additional plugin-specific options
     */
    @Builder.Default
    private Map<String, Object> additionalOptions = new HashMap<>();

    /**
     * Get an additional option.
     *
     * @param key Option key
     * @return Option value or null
     */
    public Object getAdditionalOption(String key) {
        return additionalOptions.get(key);
    }

    /**
     * Set an additional option.
     *
     * @param key Option key
     * @param value Option value
     */
    public void setAdditionalOption(String key, Object value) {
        additionalOptions.put(key, value);
    }

    /**
     * Create default send options.
     *
     * @return Default options
     */
    public static SendOptions defaults() {
        return SendOptions.builder().build();
    }

    /**
     * Create options for fire-and-forget messages.
     *
     * @return Fire-and-forget options
     */
    public static SendOptions fireAndForget() {
        return SendOptions.builder()
                .qos(0)
                .retained(false)
                .build();
    }

    /**
     * Create options for reliable delivery.
     *
     * @return Reliable delivery options
     */
    public static SendOptions reliable() {
        return SendOptions.builder()
                .qos(2)
                .retained(false)
                .build();
    }
}

