/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the Instantbird messenging client, released
 * 2011.
 *
 * The Initial Developer of the Original Code is
 * Florian QUEZE <florian@instantbird.org>.
 * Portions created by the Initial Developer are Copyright (C) 2011
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"
interface prplIConversation;

[scriptable, uuid(dae17fae-0d04-4d89-a817-637ef433383f)]
interface imICommand: nsISupports {
  readonly attribute AUTF8String name;

  // Help message displayed when the user types /help <name>.
  // Format: <command name> <parameters>: <help message>
  // Example: "help &lt;name&gt;: show the help message for the &lt;name&gt;
  //           command, or the list of possible commands when used without
  //           parameter."
  readonly attribute AUTF8String helpString;

  const short CONTEXT_IM   = 1;
  const short CONTEXT_CHAT = 2;
  const short CONTEXT_ALL  = CONTEXT_IM | CONTEXT_CHAT;
  readonly attribute long usageContext;

  const short PRIORITY_LOW     = -1000;
  const short PRIORITY_DEFAULT = 0;
  const short PRIORITY_PRPL    = 1000;
  const short PRIORITY_HIGH    = 4000;
  // Any integer value is usable as a priority.
  //    0 is the default priority.
  //  < 0 is lower priority.
  //  > 0 is higher priority.
  // Commands registered by protocol plugins will usually use PRIORITY_PRPL.
  readonly attribute long priority;

  // Will return true if the command handled the message (it should not be sent).
  // The leading slash, the command name and the following space are not included
  // in the aMessage parameter.
  boolean run(in AUTF8String aMessage,
              [optional] in prplIConversation aConversation);
};

[scriptable, uuid(467709a0-0bed-4f44-9bdc-13f78b9eaeba)]
interface imICommandsService: nsISupports {
  void initCommands();
  void unInitCommands();

  // Commands registered without a protocol id will work for all protocols.
  // Registering several commands of the same name with the same
  // protocol id or no protocol id will replace the former command
  // with the latter.
  void registerCommand(in imICommand aCommand,
                       [optional] in AUTF8String aPrplId);

  // aPrplId should be the same as what was used for the command registration.
  void unregisterCommand(in AUTF8String aCommandName,
                         [optional] in AUTF8String aPrplId);

  void listCommandsForConversation(
    [optional] in prplIConversation aConversation,
    [optional] out unsigned long commandCount,
    [retval, array, size_is(commandCount)] out imICommand commands);

  void listCommandsForProtocol(in AUTF8String aPrplId,
    [optional] out unsigned long commandCount,
    [retval, array, size_is(commandCount)] out imICommand commands);

  // Will return true if a command handled the message (it should not be sent).
  // The aConversation parameters is required to execute protocol specific
  // commands. Application global commands will work without it.
  boolean executeCommand(in AUTF8String aMessage,
                         [optional] in prplIConversation aConversation);
};

%{ C++
#define IM_COMMANDS_SERVICE_CONTRACTID \
  "@mozilla.org/chat/commands-service;1"
%}
