package io.fluxcapacitor.javaclient.eventsourcing;

import io.fluxcapacitor.common.MessageType;
import io.fluxcapacitor.common.api.Metadata;
import io.fluxcapacitor.javaclient.common.Message;

import java.util.function.Function;

public interface EsModel<T> {

    default EsModel<T> apply(Object event) {
        return apply(new Message(event, MessageType.EVENT));
    }

    default EsModel<T> apply(Object event, Metadata metadata) {
        return apply(new Message(event, metadata, MessageType.EVENT));
    }

    EsModel<T> apply(Message message);

    default EsModel<T> apply(Function<T, Message> eventFunction) {
        return apply(eventFunction.apply(get()));
    }

    T get();

    long getSequenceNumber();
}

@@ -221,16 +221,53 @@
 unction;
+%0Aimport java.util.function.Predicate;
 %0A%0Apublic
@@ -706,24 +706,255 @@
 )));%0A    %7D%0A%0A
+    default %3CE extends Exception%3E EsModel%3CT%3E ensure(Predicate%3CT%3E check, Function%3CT, E%3E errorProvider) throws E %7B%0A        if (!check.test(get())) %7B%0A            throw errorProvider.apply(get());%0A        %7D%0A        return this;%0A    %7D%0A%0A
     T get();

Add method on EsModel that enables clients to check if a command is legal