/*
 * BEGIN FLOCK GPL
 *
 * Copyright Flock Inc. 2005-2009
 * http://flock.com
 *
 * This file may be used under the terms of the
 * GNU General Public License Version 2 or later (the "GPL"),
 * http://www.gnu.org/licenses/gpl.html
 *
 * 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.
 *
 * END FLOCK GPL
 */

#include "nsISupports.idl"
#include "nsISimpleEnumerator.idl"
#include "nsIStringEnumerator.idl"
#include "nsIPropertyBag.idl"
#include "nsIDOMWindow.idl"
#include "flockIBlogWebService.idl"


[scriptable, uuid(62534b85-51a1-443d-b939-1f0a4b37d0bf)]
interface flockIBlogDraft: nsISupports {
  attribute long long id;
  attribute long long lastupdate;
  attribute AString title;
  attribute AString content;
  attribute AString tags;
};

[scriptable, uuid(30444088-8bcb-4923-a17b-a75ff39aa0ba)]
interface flockIBlogService : nsISupports {
  readonly attribute nsISimpleEnumerator services;

  // API Catalog 
  /**
   * For custom blogs only: register a new blog API (ex: MetaWeblog, ATOM)
   * @param aAPI (in) the service providing the API
   * @param aShortname (in) a unique identifier for the API
   * @return nothing
   */

  void registerAPI(in flockICustomBlogWebService aAPI, in ACString aShortname);
  /**
   * For custom blogs only: returns the service identified by aShortname
   */

  flockICustomBlogWebService getAPIFromShortname(in ACString aShortname);
  AString getShortnameFromAPI(in flockICustomBlogWebService aAPI);

  /**
   * For custom blogs only: detect the supported API for a given URL
   * (usually a Blog) and return one accounts for one of the API;
   * The list is returned through the listener
   * @param aAPI (in) the service providing the API
   * @param aShortname (in) a unique identifier for the API
   * @return nothing
   */
  void getCandidatesAPI(in flockIListener aFlockListener, in AString aUrl);

  // Accounts management

  /**
   * Return the number of configured accounts that provide at least one blog
   */
  long accountCount ();

  /**
   * Return information about the account corresponding to a blog
   * @param aBlogID (in) the URN of the blog
   * @return a wrapped JS object with the following members:
   *   blogid: the blog id, as the server understands it
   *   username: username to authenticate
   *   password: password to authenticate (may be null if authtoken is not)
   *   authtoken: authentication token (may be null if password is not)
   *   apiLink: the URL of the API
   */
  nsISupports getAccount(in AString aBlogID);

  /**
   * Return true if there is already one blog of the given name.
   * It would work fine without having blog title being unique,
   * but as it is the way it is presented to the user we try to
   * keep it unique anyway
   * @param aTitle (in) the title of the blog as displayed to the user
   * @return true if an account of this name exists, false otherwise
   */

  boolean accountExists (in AString aTitle);
  /**
   * Save the account to flock-data, and the password in the password manager
   * @param aAccountID (in) the account to which the blog is attached
   * @param aBlogId (in) the id of the blog, relative to the account
   * @param aBlogAccount (in) 
   */

  AString getDefaultBlog ();

  /**
   * Set the default blog 
   */
  void setDefaultBlog (in AString aBlogID);

  void addCategory (in AString aBlogID, in AString aCategoryId, in AString aCategoryName);

  // Editor
  /**
   * Open a given post in a new blog editor window. If the post is already open,
   * the existing window is focused and no new window is open.
   * @param aId (in) the URN of the post to open
   */
  void openPost(in AString aId);

  /**
   * Open a new blog editor window.
   * @param aTitle (in) the initial value of the title field. If this attribute is the empty string (""), a default is used ("Untitled" for English)
   * @param aContent (in) the initial value of the post content. It can be empty ("").
   * @param aTags (in) the initial value of the tags field. It can be empty but if it is not, tags must be separated by commas.
   */
  nsIDOMWindow openEditor(in AString aTitle, in AString aContent, in AString aTags);

  /**
   * Returns true if at least one blog editor window is open, false otherwise.
   */
  boolean editorIsOpen();

  // Blog drafts
  long long saveDraft(in long long aId, in AString aTitle, in AString aContent, in AString aTags);
  void removeDraft(in long long aId);
  void moveTo(in long long aId, in AString aFolderId);
  nsISimpleEnumerator getDraftsFrom(in AString aFolderId);
  flockIBlogDraft getDraft(in long long aDraftId);

  // Blog recovery
  string saveRecovery(in long long aId, in AString aTitle, in AString aContent, in AString aTags);
  void removeRecovery(in long long aId);
  nsISimpleEnumerator getAllRecovery();

  /**
   * Delete any existing recovery draft
   * @return nothing
   */
  void looseRecovery();

  // Notifications
  void addNotification (in AString aURL);
  void removeNotification (in AString aURL);
  nsIStringEnumerator getNotifications ();
};
