/* 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 "calIOperation.idl"

interface calICalendar;
interface calIGoogleSession;
interface calIGoogleCalendar;
interface calIGenericOperationListener;
interface calIOperationListener;
interface calIDateTime;
interface calIItemBase;

interface nsIVariant;

[scriptable, uuid(53a3438a-21bc-4a0f-b813-77a8b4f19282)]
interface calIGoogleRequest : calIOperation {

    const unsigned long LOGIN = 0;
    const unsigned long ADD = 1;
    const unsigned long MODIFY = 2;
    const unsigned long DELETE = 3;
    const unsigned long GET = 4;

    /**
     * The type of request. Must be one of the above constants.
     */
    attribute PRUint32 type;

    /**
     * The request uri string
     */
    attribute AUTF8String uri;

    /**
     * The operation listener. This is not called by the request object, but can
     * be used by the response listener to call the original listener that
     * caused the request
     */
    attribute calIOperationListener operationListener;

    /**
     * The response listener. This will be called as soon as the request to
     * google has completed.
     */
    attribute calIGenericOperationListener responseListener;

    /**
     * The calendar that initiated the request
     */
    attribute calIGoogleCalendar calendar;

    /**
     * The destination calendar, used for synchronization runs.
     */
    attribute calICalendar destinationCal;

    /**
     * If set to false, an authentication failure should not cause any dialogs
     * to show up that cause reauthentication, but the failure should be
     * returned directly.
     *
     * This attribute defaults to true.
     */
    attribute boolean reauthenticate;

    /**
     * Various options to be carried through to the response listener.
     * XXX The corresponding options are not set up automatically just by
     * setting these options. You still need to use addQueryParameter to filter
     * by item range or other property.
     */
    attribute calIDateTime itemRangeStart;
    attribute calIDateTime itemRangeEnd;
    attribute unsigned long itemFilter;
    attribute AUTF8String itemId;
    attribute boolean useCache;

    /**
     * For add/modify/delete item requests, these contain the old and new items.
     */
    attribute calIItemBase newItem;
    attribute calIItemBase oldItem;

    /**
     * Set up some upload data using the given content type
     *
     * @param aContentType      The value of the content type header to be set.
     * @param aData             The Data to be uploaded.
     */
    void setUploadData(in AUTF8String aContentType, in AUTF8String aData);

    /**
     * Adds a query parameter to the request. These will be escaped.
     *
     * @param aKey      The key of the query parameter.
     * @param aValue    The value of the query parameter.
     */
    void addQueryParameter(in AUTF8String aKey, in AUTF8String aValue);

    /**
     * Run the request, using the specified session.
     *
     * @param aSession      The session to request with.
     */
    void commit(in calIGoogleSession aSession);

    /**
     * Tell listeners that the operation failed
     *
     * @param aCode     The error code to use.
     * @param aMessage  The error message to use.
     */
    void fail(in PRUint32 aCode, in AUTF8String aMessage);

    /**
     * Tell listeners that the operation succeeded.
     *
     * @param aMessage  The error message to use.
     */
    void succeed(in AUTF8String aMessage);
};
