package com.timgroup.eventsubscription.healthcheck;

import com.timgroup.eventstore.api.Position;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

public final class InitialCatchupFuture extends CompletableFuture<Position> implements SubscriptionListener {
    @Override
    public void caughtUpAt(Position position) {
        complete(position);
    }

    @Override
    public void staleAtVersion(Optional<Position> position) {
    }

    @Override
    public void terminated(Position position, Exception e) {
        completeExceptionally(new InitialCatchupFailedException(position, e));
    }

    public static final class InitialCatchupFailedException extends CompletionException {
        private final Position position;

        InitialCatchupFailedException(Position position, Throwable cause) {
            super("Initial catchup failed at " + position, cause);
            this.position = position;
        }

        public Position getPosition() {
            return position;
        }
    }
}

@@ -95,576 +95,1623 @@
 on;%0A
-%0Aimport java.util.Optional;%0Aimport java.util.concurrent.CompletableFuture;%0Aimport java.util.concurrent.CompletionException;%0A%0Apublic final class InitialCatchupFuture extends CompletableFuture%3CPosition%3E implements SubscriptionListener %7B%0A    @Override%0A    public void caughtUpAt(Position position) %7B%0A        complete(position);%0A    %7D%0A%0A    @Override%0A    public void staleAtVersion(Optional%3CPosition%3E position) %7B%0A    %7D%0A%0A    @Override%0A    public void terminated(Position position, Exception e) %7B%0A        completeExceptionally(new InitialCatchupFailedException(position, e));
+import com.timgroup.eventsubscription.Event;%0Aimport com.timgroup.eventsubscription.EventHandler;%0Aimport com.timgroup.eventsubscription.lifecycleevents.InitialCatchupCompleted;%0Aimport com.timgroup.eventsubscription.lifecycleevents.SubscriptionTerminated;%0A%0Aimport java.util.Optional;%0Aimport java.util.concurrent.CompletableFuture;%0Aimport java.util.concurrent.CompletionException;%0A%0Apublic final class InitialCatchupFuture extends CompletableFuture%3CPosition%3E implements SubscriptionListener, EventHandler %7B%0A    private final EventHandler downstream;%0A%0A    public InitialCatchupFuture() %7B%0A        this(EventHandler.DISCARD);%0A    %7D%0A%0A    public InitialCatchupFuture(EventHandler downstream) %7B%0A        this.downstream = downstream;%0A    %7D%0A%0A    @Override%0A    public void caughtUpAt(Position position) %7B%0A        complete(position);%0A    %7D%0A%0A    @Override%0A    public void staleAtVersion(Optional%3CPosition%3E position) %7B%0A    %7D%0A%0A    @Override%0A    public void terminated(Position position, Exception e) %7B%0A        completeExceptionally(new InitialCatchupFailedException(position, e));%0A    %7D%0A%0A    @Override%0A    public void apply(Position position, Event deserialized) %7B%0A        downstream.apply(position, deserialized);%0A        if (deserialized instanceof InitialCatchupCompleted) %7B%0A            complete(position);%0A        %7D%0A        else if (deserialized instanceof SubscriptionTerminated) %7B%0A            SubscriptionTerminated subscriptionTerminated = (SubscriptionTerminated) deserialized;%0A            completeExceptionally(new InitialCatchupFailedException(subscriptionTerminated.position, subscriptionTerminated.exception));%0A        %7D
 %0A   
@@ -1854,16 +1854,23 @@
         
+public 
 InitialC

support InitialCatchupFuture as an EventHandler to maybe ease transition