/*
 * Copyright 2018 Red Hat, Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * The Apache License v2.0 is available at
 * http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 */
package io.vertx.redis.client;

import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.redis.client.impl.CommandImpl;

/**
 * <b>Auto generated</b> API Commands to interact with REDIS.
 *
 * @author <a href="mailto:plopes@redhat.com">Paulo Lopes</a>
 */
@VertxGen
public interface Command {

{{#each .}}
  Command {{ enum }} = Command.create("{{ name }}", {{ arity }}, {{ firstKey }}, {{ lastKey }}, {{ interval }}, {{ write }}, {{ readOnly }}, {{ movable }}, {{ pubsub }});
{{/each}}
  Command SENTINEL = Command.create("sentinel");

  /**
   * Creates a Redis Command from METADATA. The metadata comes from the REDIS command "COMMAND"
   * https://redis.io/commands/command
   *
   * Each top-level result contains six nested results. Each nested result is:
   *
   *     command name
   *     command arity specification
   *     nested Array reply of command flags
   *     position of first key in argument list
   *     position of last key in argument list
   *     step count for locating repeating keys
   *
   * @param command command name
   * @param arity arity
   * @param firstKey position of the first key
   * @param lastKey position of the last key
   * @param interval step count for locating repeating keys
   * @param write write flag extracted from the nested Array reply of command flags
   * @param readOnly readOnly flag extracted from the nested Array reply of command flags
   * @param movable movable flag extracted from the nested Array reply of command flags
   * @param pubsub flag extracted from the nested Array reply of command flags
   * @return a command instance
   */
  static Command create(String command, int arity, int firstKey, int lastKey, int interval, boolean write, boolean readOnly, boolean movable, boolean pubsub) {
    return new CommandImpl(command, arity, firstKey, lastKey, interval, write, readOnly, movable, pubsub);
  }

  /**
   * Generic command generator for extensions.
   *
   * @param command
   * @return the cachable immutable command instance
   */
  static Command create(String command) {
    return new CommandImpl(command, -1, 0, 0, 0, false, false, false, false);
  }

  @GenIgnore(GenIgnore.PERMITTED_TYPE)
  byte[] getBytes();

  int getArity();

  boolean isMultiKey();

  int getFirstKey();

  int getLastKey();

  int getInterval();

  boolean isKeyless();

  boolean isWrite();

  boolean isReadOnly();

  boolean isMovable();

  boolean isVoid();

  boolean isPubSub();
}
