package replicant;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

/**
 * A message fragment defining an action on a channel.
 */
@JsType( isNative = true, namespace = JsPackage.GLOBAL, name = "Object" )
public class ChannelAction
{
  public enum Action
  {
    ADD, REMOVE, UPDATE
  }

  private int cid;
  @Nullable
  private Double scid;
  private String action;
  @Nullable
  private Object filter;

  /**
   * Create a ChannelAction.
   *
   * @return the new ChannelAction.
   */
  @JsOverlay
  public static ChannelAction create( final int cid,
                                      final int scid,
                                      @Nonnull final Action action,
                                      @Nullable final Object filter )
  {
    final ChannelAction channel = new ChannelAction();
    channel.cid = cid;
    channel.scid = (double) scid;
    channel.action = action.name().toLowerCase();
    channel.filter = filter;
    return channel;
  }

  /**
   * @return the id of the Channel.
   */
  @JsOverlay
  public final int getChannelId()
  {
    return cid;
  }

  /**
   * @return true if the reference has a SubChannel id present.
   */
  @JsOverlay
  public final boolean hasSubChannelId()
  {
    return null != scid;
  }

  /**
   * Return the sub-channel id.
   * This method should not be invoked unless {@link #hasSubChannelId()} returns true.
   *
   * @return the sub-channel id.
   */
  @JsOverlay
  public final int getSubChannelId()
  {
    assert null != scid;
    return scid.intValue();
  }

  @JsOverlay
  @Nonnull
  public final Action getAction()
  {
    return Action.valueOf( action.toUpperCase() );
  }

  @Nullable
  @JsOverlay
  public final Object getChannelFilter()
  {
    return filter;
  }
}

@@ -687,62 +687,8 @@
 id,%0A
-                                      final int scid,%0A
     
@@ -751,16 +751,16 @@
 action,%0A
+
         
@@ -907,42 +907,8 @@
 id;%0A
-    channel.scid = (double) scid;%0A
     
@@ -949,24 +949,24 @@
 owerCase();%0A
-
     channel.
@@ -1003,24 +1003,492 @@
 annel;%0A  %7D%0A%0A
+  /**%0A   * Create a ChannelAction.%0A   *%0A   * @return the new ChannelAction.%0A   */%0A  @JsOverlay%0A  public static ChannelAction create( final int cid,%0A                                      final int scid,%0A                                      @Nonnull final Action action,%0A                                      @Nullable final Object filter )%0A  %7B%0A    final ChannelAction channel = create( cid, action, filter );%0A    channel.scid = (double) scid;%0A    return channel;%0A  %7D%0A%0A
   /**%0A   * @

Add factory method for scenario where there is no subChannel