/*
    SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#pragma once

#include "collection.h"
#include "item.h"
#include "standardactionmanager.h"

namespace Akonadi
{
/**
 * \short A helper class to manage action states.
 *
 * \author Tobias Koenig <tokoe@kde.org>
 */
class ActionStateManager
{
public:
    /*
     * Creates a new action state manager.
     */
    explicit ActionStateManager() = default;

    virtual ~ActionStateManager() = default;

    /**
     * Updates the states according to the selected collections and items.
     * \param collections selected collections (from the folder tree)
     * \param favoriteCollections selected collections (among the ones marked as favorites)
     * \param items selected items
     * \param clipboardUrls content of the clipboard (list of URLs)
     */
    void
    updateState(const Collection::List &collections, const Collection::List &favoriteCollections, const Item::List &items, const QList<QUrl> &clipboardUrls);

    /**
     * Sets the \p receiver object that will actually update the states.
     *
     * The object must provide the following three slots:
     *   - void enableAction( int, bool )
     *   - void updatePluralLabel( int, int )
     *   - bool isFavoriteCollection( const Akonadi::Collection& )
     * \param receiver object that will actually update the states.
     */
    void setReceiver(StandardActionManagerPrivate *receiver);

protected:
    virtual bool isRootCollection(const Collection &collection) const;
    virtual bool isResourceCollection(const Collection &collection) const;
    virtual bool isFolderCollection(const Collection &collection) const;
    virtual bool isSpecialCollection(const Collection &collection) const;
    virtual bool isFavoriteCollection(const Collection &collection) const;
    virtual bool hasResourceCapability(const Collection &collection, const QString &capability) const;
    virtual bool collectionCanHaveItems(const Collection &collection) const;

    virtual void enableAction(StandardActionManager::Type action, bool state);
    virtual void updatePluralLabel(StandardActionManager::Type action, int count);
    virtual void updateAlternatingAction(StandardActionManager::Type action);

private:
    Q_DISABLE_COPY_MOVE(ActionStateManager)

    StandardActionManagerPrivate *mReceiver = nullptr;
};

}
