package inn.ocsf.bee.freigeld.core.model;

import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public interface Emitter {

    default void emit(long count, @NotNull CoinValue value) {
        emit(count, value, 0);
    }

    default Collection<UUID> emit(@NotNull Collection<Coin> futureCoins) {
        return futureCoins.stream().peek(c -> {
            if (c.getId() != null) throw new RuntimeException("only future coins");
        }).map(this::emitOne).collect(Collectors.toList());
    }

    void emit(long count, @NotNull CoinValue value, int era);

    UUID emitOne(@NotNull Coin coin);

    default void free(@NotNull Collection<Coin> coins) {
        coins.forEach(this::free);
    }

    void free(@NotNull Coin coin);

    void listen(@NotNull Consumer<EmitterEvent> fn);

    CompletableFuture<EmitterEvent> calc();

}
