package com.r35157.service.notification;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.Objects;

/**
 * Sends notification messages to explicitly supplied destinations.
 *
 * @param <D> transport-specific destination configuration
 */
public interface AddressedNotificationService<
        D extends NotificationDestination>
{
    /**
     * Sends a notification message to a destination.
     *
     * @param destination the destination configuration
     * @param message the non-blank notification text
     * @throws IllegalArgumentException if {@code message} is {@code null},
     *                                  empty, or blank
     * @throws IOException if synchronous notification delivery fails
     */
    void push(
            @NotNull D destination,
            @NotNull ΩNotificationMessageΩ message
    ) throws IOException;

    /**
     * Binds a destination into a transport-independent notification service.
     *
     * @param destination the destination configuration to capture
     * @return a service that requires only a notification message
     * @throws NullPointerException if {@code destination} is {@code null}
     */
    default @NotNull BoundNotificationService bind(@NotNull D destination) {
        Objects.requireNonNull(destination, "destination");
        return message -> push(destination, message);
    }
}
