/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#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);
};
