// SPDX-License-Identifier: LGPL-2.1-or-later
//
// SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
//

#ifndef MARBLE_CACHESTORAGEPOLICY_H
#define MARBLE_CACHESTORAGEPOLICY_H

#include "DiscCache.h"
#include "StoragePolicy.h"

#include <QString>

#include "marble_export.h"

class QByteArray;

namespace Marble
{

class MARBLE_EXPORT CacheStoragePolicy : public StoragePolicy
{
    Q_OBJECT

public:
    /**
     * Creates a new cache storage policy.
     *
     * @param cacheDirectory The directory which shall be used for the cache.
     */
    explicit CacheStoragePolicy(const QString &cacheDirectory);

    /**
     * Destroys the cache storage policy.
     */
    ~CacheStoragePolicy() override;

    /**
     * Returns whether the @p fileName exists already.
     */
    bool fileExists(const QString &fileName) const override;

    /**
     * Updates the @p fileName with the given @p data.
     */
    bool updateFile(const QString &fileName, const QByteArray &data) override;

    /**
     * Clears the cache.
     */
    void clearCache() override;

    /**
     * Returns the last error message.
     */
    QString lastErrorMessage() const override;

    /**
     * Returns the data of a file.
     */
    QByteArray data(const QString &fileName);

    /**
     * Sets the limit of the cache in @p bytes.
     */
    void setCacheLimit(quint64 bytes);

    /**
     * Returns the limit of the cache in bytes.
     */
    quint64 cacheLimit() const;

private:
    DiscCache m_cache;
    QString m_errorMsg;
};

}

#endif
