/* ***** 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
 * 2007.
 *
 * The Initial Developer of the Original Code is
 * Florian QUEZE <florian@instantbird.org>.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * 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"
#include "prplIConversation.idl"
#include "imIUserStatusInfo.idl"

interface imITag;
interface imIBuddy;
interface imIAccountBuddy;
interface imIAccount;
interface prplIProtocol;
interface purpleIProxyInfo;

/*
 * Used to join chat rooms.
 */

[ptr] native GHashTablePtr(GHashTable);

[scriptable, uuid(ea7ab156-d25e-46cc-93ef-29f77b3c0795)]
interface prplIChatRoomFieldValues: nsISupports {
  AUTF8String getValue(in AUTF8String aIdentifier);
  void setValue(in AUTF8String aIdentifier, in AUTF8String aValue);

  [noscript] readonly attribute GHashTablePtr hashTable;
};

[scriptable, uuid(19dff981-b125-4a70-bc1a-efc783d07137)]
interface prplIChatRoomField: nsISupports {
  readonly attribute AUTF8String label;
  readonly attribute AUTF8String identifier;
  readonly attribute boolean required;

  const short TYPE_TEXT = 0;
  const short TYPE_PASSWORD = 1;
  const short TYPE_INT = 2;

  readonly attribute short type;
  readonly attribute long min;
  readonly attribute long max;
};


/*
 * This interface should be implemented by the protocol plugin.
 */
[scriptable, uuid(fb1b29cb-63ba-4335-9f44-63aea3f616a3)]
interface prplIAccount: nsISupports {
  readonly attribute imIAccount imAccount;

  // observe should only be called by the imIAccount
  // implementation to report user status changes that affect this account.
  void observe(in nsISupports aObj, in string aEvent,
               [optional] in wstring aData);

  /* Uninitialize the prplIAccount instance. This is typically done
     automatically at shutdown (by the core service) or as part of
     the 'remove' method. */
  void unInit();

  void connect();
  void disconnect();

  prplIConversation createConversation(in AUTF8String aName);

  // Used when the user wants to add a buddy to the buddy list
  void addBuddy(in imITag aTag, in AUTF8String aName);

  // Used while loading the buddy list at startup.
  imIAccountBuddy loadBuddy(in imIBuddy aBuddy, in imITag aTag);

  /* Request more info on a buddy (typically a chat buddy).
   * The result (if any) will be provided by a user-info-received
   * notification dispatched through the observer service:
   *  - aSubject will be an nsISimpleEnumerator of prplITooltipInfo.
   *  - aData will be aBuddyName.
   */
  void requestBuddyInfo(in AUTF8String aBuddyName);

  readonly attribute boolean canJoinChat;
  nsISimpleEnumerator getChatRoomFields();
  prplIChatRoomFieldValues getChatRoomDefaultFieldValues([optional] in AUTF8String aDefaultChatName);
  /*
   * Create a new chat conversation if it doesn't already exist.
   */
  void joinChat(in prplIChatRoomFieldValues aComponents);

  readonly attribute AUTF8String normalizedName;

  attribute purpleIProxyInfo proxyInfo;

  // protocol specific options: those functions set the protocol
  // specific options for the PurpleAccount
  void setBool(in string aName, in boolean aVal);
  void setInt(in string aName, in long aVal);
  void setString(in string aName, in AUTF8String aVal);

  /* When a connection error occurred, this value indicates the type of error */
  readonly attribute short connectionErrorReason;

  /* Possible connection error reasons:
     ERROR_NETWORK_ERROR and ERROR_ENCRYPTION_ERROR are not fatal and
     should enable the automatic reconnection feature. */
  const short NO_ERROR = -1;
  const short ERROR_NETWORK_ERROR = 0;
  const short ERROR_INVALID_USERNAME = 1;
  const short ERROR_AUTHENTICATION_FAILED = 2;
  const short ERROR_AUTHENTICATION_IMPOSSIBLE = 3;
  const short ERROR_NO_SSL_SUPPORT = 4;
  const short ERROR_ENCRYPTION_ERROR = 5;
  const short ERROR_NAME_IN_USE = 6;
  const short ERROR_INVALID_SETTINGS = 7;
  const short ERROR_CERT_NOT_PROVIDED = 8;
  const short ERROR_CERT_UNTRUSTED = 9;
  const short ERROR_CERT_EXPIRED = 10;
  const short ERROR_CERT_NOT_ACTIVATED = 11;
  const short ERROR_CERT_HOSTNAME_MISMATCH = 12;
  const short ERROR_CERT_FINGERPRINT_MISMATCH = 13;
  const short ERROR_CERT_SELF_SIGNED = 14;
  const short ERROR_CERT_OTHER_ERROR = 15;
  const short ERROR_OTHER_ERROR = 16;

  /* From PurpleConnectionFlags */

  //   PURPLE_CONNECTION_HTML
  //    Connection sends/receives in 'HTML'.
  readonly attribute boolean HTMLEnabled;

  // libpurple expects messages to be HTML escaped even when HTML
  // isn't enabled. Our js-prpls most likely don't want that behavior.
  readonly attribute boolean HTMLEscapePlainText;

  //   PURPLE_CONNECTION_NO_BGCOLOR
  //    Connection does not send/receive background colors.
  readonly attribute boolean noBackgroundColors;

  //   PURPLE_CONNECTION_AUTO_RESP
  //    Send auto responses when away.
  readonly attribute boolean autoResponses;

  //   PURPLE_CONNECTION_FORMATTING_WBFO
  //    The text buffer must be formatted as a whole.
  readonly attribute boolean singleFormatting;

  //   PURPLE_CONNECTION_NO_NEWLINES
  //    No new lines are allowed in outgoing messages.
  readonly attribute boolean noNewlines;

  //   PURPLE_CONNECTION_NO_FONTSIZE
  //    Connection does not send/receive font sizes.
  readonly attribute boolean noFontSizes;

  //   PURPLE_CONNECTION_NO_URLDESC
  //    Connection does not support descriptions with links.
  readonly attribute boolean noUrlDesc;

  //   PURPLE_CONNECTION_NO_IMAGES
  //    Connection does not support sending of images.
  readonly attribute boolean noImages;

  // This is currently used only by Twitter.
  readonly attribute long maxMessageLength;
};

/* This interface should be implemented by the im core. It inherits
from prplIAccount and in most cases will forward the calls for the
inherited members to a prplIAccount account instance implemented by
the protocol plugin. */
[scriptable, uuid(20a85b44-e220-4f23-85bf-f8523d1a2b08)]
interface imIAccount: prplIAccount {
  /* Check if autologin is enabled for this account, connect it now. */
  void checkAutoLogin();

  /* Cancel the timer that automatically reconnects the account if it was
     disconnected because of a non fatal error. */
  void cancelReconnection();

  readonly attribute AUTF8String name;
  readonly attribute AUTF8String id;
  readonly attribute unsigned long numericId;
  readonly attribute prplIProtocol protocol;
  readonly attribute prplIAccount prplAccount;

  // Save account specific preferences to disk.
  void save();

  attribute boolean autoLogin;

  /* This is the value when the preference firstConnectionState is not set.
     It indicates that the account has already been successfully connected at
     least once with the current parameters. */
  const short FIRST_CONNECTION_OK = 0;
  /* Set when the account has never had a successful connection
     with the current parameters */
  const short FIRST_CONNECTION_UNKNOWN = 1;
  /* Set when the account is trying to connect for the first time
     with the current parameters (removed after a successsful connection) */
  const short FIRST_CONNECTION_PENDING = 2;
  /* Set at startup when the previous state was pending */
  const short FIRST_CONNECTION_CRASHED = 4;

  attribute short firstConnectionState;

  // Passwords are stored in the toolkit Password Manager.
  attribute AUTF8String password;

  attribute AUTF8String alias;

  /* While an account is connecting, this attribute contains a message
     indicating the current step of the connection */
  readonly attribute AUTF8String connectionStateMsg;

  /* Number of the reconnection attempt
   *  0 means that no automatic reconnection currently pending
   *  n means the nth reconnection attempt is pending
   */
  readonly attribute unsigned short reconnectAttempt;

  /* Time stamp of the next reconnection attempt */
  readonly attribute long long timeOfNextReconnect;

  /* Time stamp of the last connection (value not reliable if not connected) */
  readonly attribute long long timeOfLastConnect;

  /* Additional possible connection error reasons:
   * (Use a big enough number that it can't conflict with error
   *  codes used in prplIAccount).
   */
  const short ERROR_UNKNOWN_PRPL = 42;
  const short ERROR_CRASHED = 43;
  const short ERROR_MISSING_PASSWORD = 44;

  /* A message describing the connection error */
  readonly attribute AUTF8String connectionErrorMessage;

  /* Info about the connection state and flags */
  const short STATE_DISCONNECTED = 0;
  const short STATE_CONNECTED = 1;
  const short STATE_CONNECTING = 2;
  const short STATE_DISCONNECTING = 3;

  readonly attribute short connectionState;

  /* The following 4 properties use the above connectionState value. */
  readonly attribute boolean disconnected;
  readonly attribute boolean connected;
  readonly attribute boolean connecting;
  readonly attribute boolean disconnecting;

  /* The imIUserStatusInfo instance this account should observe for
     status changes. When this is null (the default value), the
     account will observe the global status. */
  attribute imIUserStatusInfo observedStatusInfo;
  // Same as above, but never null (it fallbacks to the global status info).
  attribute imIUserStatusInfo statusInfo;

  // imIAccount also implements an observe method but this
  // observe should only be called by the prplIAccount
  // implementations to report connection status changes.
};
