package replicant.spy.tools;

import elemental2.dom.DomGlobal;
import javax.annotation.Nonnull;
import org.realityforge.anodoc.Unsupported;
import replicant.spy.AreaOfInterestCreatedEvent;

/**
 * A SpyEventHandler that prints spy events to the tools console.
 * The events are colored to make them easy to digest. This class is designed to be easy to sub-class.
 */
@Unsupported( "This class relies on unstable spy API and will likely evolve as the api evolves" )
public class ConsoleSpyEventProcessor
  extends AbstractSpyEventProcessor
{
  @CssRules
  private static final String ENTITY_COLOR = "color: #CF8A3B; font-weight: normal;";
  @CssRules
  private static final String SUBSCRIPTION_COLOR = "color: #0FA13B; font-weight: normal;";
  @CssRules
  private static final String AREA_OF_INTEREST_COLOR = "color: #006AEB; font-weight: normal;";
  @CssRules
  private static final String ERROR_COLOR = "color: #A10001; font-weight: normal;";

  /**
   * Create the processor.
   */
  public ConsoleSpyEventProcessor()
  {
    on( AreaOfInterestCreatedEvent.class, this::onAreaOfInterestCreated );
  }

  /**
   * Handle the AreaOfInterestCreatedEvent.
   *
   * @param e the event.
   */
  protected void onAreaOfInterestCreated( @Nonnull final AreaOfInterestCreatedEvent e )
  {
    log( "%cAreaOfInterest Created " + e.getAreaOfInterest().getChannel(), AREA_OF_INTEREST_COLOR );
  }

  /**
   * Log specified message with parameters
   *
   * @param message the message.
   * @param styling the styling parameter. It is assumed that the message has a %c somewhere in it to identify the start of the styling.
   */
  protected void log( @Nonnull final String message,
                      @CssRules @Nonnull final String styling )
  {
    DomGlobal.console.log( message, styling );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  protected void handleUnhandledEvent( @Nonnull final Object event )
  {
    DomGlobal.console.log( event );
  }
}

@@ -154,29 +154,183 @@
 ant.
-spy.AreaOfInterestCre
+Channel;%0Aimport replicant.FilterUtil;%0Aimport replicant.spy.AreaOfInterestCreatedEvent;%0Aimport replicant.spy.AreaOfInterestDisposedEvent;%0Aimport replicant.spy.AreaOfInterestUpd
 ated
@@ -1242,24 +1242,176 @@
 tCreated );%0A
+    on( AreaOfInterestUpdatedEvent.class, this::onAreaOfInterestUpdated );%0A    on( AreaOfInterestDisposedEvent.class, this::onAreaOfInterestDisposed );%0A
   %7D%0A%0A  /**%0A 
@@ -1589,75 +1589,1106 @@
     
-log( %22%25cAreaOfInterest Created %22 + e.getAreaOfInterest().getChannel
+final Channel channel = e.getAreaOfInterest().getChannel();%0A    final Object filter = channel.getFilter();%0A    final String filterPrefix = null == filter ? %22%22 : %22 - %22;%0A    final String filterString = FilterUtil.filterToString( filter );%0A    log( %22%25cAreaOfInterest Created %22 + channel.getAddress() + filterPrefix + filterString, AREA_OF_INTEREST_COLOR );%0A  %7D%0A%0A  /**%0A   * Handle the AreaOfInterestUpdatedEvent.%0A   *%0A   * @param e the event.%0A   */%0A  protected void onAreaOfInterestUpdated( @Nonnull final AreaOfInterestUpdatedEvent e )%0A  %7B%0A    final Channel channel = e.getAreaOfInterest().getChannel();%0A    final Object filter = channel.getFilter();%0A    final String filterString = FilterUtil.filterToString( filter );%0A    log( %22%25cAreaOfInterest Updated %22 + channel.getAddress() + %22 - %22 + filterString, AREA_OF_INTEREST_COLOR );%0A  %7D%0A%0A  /**%0A   * Handle the AreaOfInterestDisposedEvent.%0A   *%0A   * @param e the event.%0A   */%0A  protected void onAreaOfInterestDisposed( @Nonnull final AreaOfInterestDisposedEvent e )%0A  %7B%0A    log( %22%25cAreaOfInterest Disposed %22 + e.getAreaOfInterest().getChannel().getAddress
 (), 

Handle other AreaOfInterest spy events