/* ***** 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 Sun Microsystems code.
 *
 * The Initial Developer of the Original Code is
 * Sun Microsystems, Inc.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Daniel Boelzle <daniel.boelzle@sun.com>
 *
 * 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 calIDateTime;
interface calIPeriod;
interface calIOperation;
interface calIGenericOperationListener;

[scriptable, uuid(EB24424C-DD22-4306-9379-FA098C61F5AF)]
interface calIFreeBusyProvider : nsISupports
{
    /**
     * Gets free/busy intervals.
     * Results are notified to the passed listener interface.
     *
     * @param aCalId      calid or MAILTO:rfc822addr
     * @param aRangeStart start time of free-busy search
     * @param aRangeEnd   end time of free-busy search
     * @param aBusyTypes  what free-busy intervals should be returned
     * @param aListener   called with an array of calIFreeBusyInterval objects
     * @return            optional operation handle to track the operation
     */
    calIOperation getFreeBusyIntervals(in AUTF8String aCalId,
                                       in calIDateTime aRangeStart,
                                       in calIDateTime aRangeEnd,
                                       in unsigned long aBusyTypes,
                                       in calIGenericOperationListener aListener);
};

/**
 * This interface reflects a free or busy interval in time.
 * Referring to RFC 2445, section 4.2.9, for the different types.
 */
[scriptable, uuid(CCBEAF5E-DB87-4bc9-8BB7-24754B76BCB5)]
interface calIFreeBusyInterval : nsISupports
{
    /**
     * The calId this free-busy period belongs to.
     */
    readonly attribute AUTF8String calId;

    /**
     * The free-busy time interval.
     */
    readonly attribute calIPeriod interval;

    /**
     * The value UNKNOWN indicates that the free-busy information for the time interval is
     * not known.
     */
    const unsigned long UNKNOWN = 0;

    /**
     * The value FREE indicates that the time interval is free for scheduling.
     */
    const unsigned long FREE = 1;

    /**
     * The value BUSY indicates that the time interval is busy because one
     * or more events have been scheduled for that interval.
     */
    const unsigned long BUSY = 1 << 1;

    /**
     * The value BUSY_UNAVAILABLE indicates that the time interval is busy
     * and that the interval can not be scheduled.
     */
    const unsigned long BUSY_UNAVAILABLE = 1 << 2;

    /**
     * The value BUSY_TENTATIVE indicates that the time interval is busy because
     * one or more events have been tentatively scheduled for that interval.
     */
    const unsigned long BUSY_TENTATIVE = 1 << 3;

    /**
     * All BUSY* states.
     */
    const unsigned long BUSY_ALL = (BUSY |
                                    BUSY_UNAVAILABLE |
                                    BUSY_TENTATIVE);

    /**
     * One of the above types.
     */
    readonly attribute unsigned long freeBusyType;
};

/**
 * This service acts as a central access point for free-busy lookup.
 * A free-busy request will be multiplexed to all added free-busy providers.
 * Adding a free-busy provider is transient.
 */
[scriptable, uuid(BE1796CF-CB53-482e-8942-D6CAA0A11BAA)]
interface calIFreeBusyService : calIFreeBusyProvider
{
    /**
     * Adds a new free-busy provider.
     */
    void addProvider(in calIFreeBusyProvider aProvider);

    /**
     * Removes a free-busy provider.
     */
    void removeProvider(in calIFreeBusyProvider aProvider);
};
