/* 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 nsITransactionManager;
interface calICalendar;
interface calIItemBase;
interface calIOperationListener;

/**
 * calITransactionManager is a service designed to handle nsITransactions
 * regarding the calendar.  It is here as a service so that we can keep the
 * transactions around without holding onto the whole global js scope+window.
 */
[scriptable, uuid(40a1ccf4-5f54-4815-b842-abf06f84dbfd)]
interface calITransactionManager : nsISupports
{
    /**
     * @param aAction       The Action to execute. This can be one of:
     *                        add     Adds an item
     *                        modify  Modfifies an item
     *                        delete  Deletes an item
     *                        move    Move an item from one calendar to the
     *                                next. With this operation, aCalendar is
     *                                the calendar that the event should be
     *                                moved to.
     * @param aCalendar     The Calendar to execute the transaction on
     * @param aItem         The changed item for this transaction. This item 
     *                      should be immutable
     * @param aOldItem      The Item in its original form. Only needed for 
     *                      modify.
     * @param aListener     The listener to call when the transaction has
     *                      completed. This parameter can be null.
     */
    void createAndCommitTxn(in AUTF8String aAction,
                            in calIItemBase aItem,
                            in calICalendar aCalendar,
                            in calIItemBase aOldItem,
                            in calIOperationListener aListener);

    /**
     * Signals the transaction manager that a series of transactions are going
     * to be performed, but that, for the purposes of undo and redo, they should
     * all be regarded as a single transaction. See also
     * nsITransactionManager::beginBatch
     */
    void beginBatch();

    /**
     * Ends the batch transaction in process. See also
     * nsITransactionManager::endBatch
     */
    void endBatch();

    /**
     * Undo the last transaction in the transaction manager's stack
     */
    void undo();

    /**
     * Returns true if it is possible to undo a transaction at this time
     */
    boolean canUndo();

    /**
     * Redo the last transaction
     */
    void redo();

    /**
     * Returns true if it is possible to redo a transaction at this time
     */
    boolean canRedo();

    /**
     * A reference to the transaction manager for calendar operations
     */
    readonly attribute nsITransactionManager transactionManager;
};
