/*******************************************************************************
***  This file is part of Dux Rei Nummariae.                                 ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021                              ***
***  John Schneiderman <Licensing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Affero General Public License as published   ***
***  by the Free Software Foundation, either version 3 of the License, or    ***
***  (at your option) any later version.                                     ***
***                                                                          ***
***  This program is distributed in the hope that it will be useful, but     ***
***  WITHOUT ANY WARRANTY; without even the implied warranty of              ***
***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    ***
***  See the GNU Affero General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Affero General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#ifndef DRN_FILE_STORAGE_EXCHANGERATESFILE_H_
#define DRN_FILE_STORAGE_EXCHANGERATESFILE_H_

#include <QString>

#include "file-storage_export.h"


namespace drn
{
namespace conversion
{

class ConversionMap;

}
namespace file_storage
{

/**
 * @brief The manager for interacting with the cached exchange rates file. This is stored under the
 * operating systems' cache directory with the name "exchange-rates.dat".
 */
class DRN_FILE_STORAGE_EXPORT ExchangeRatesFile
{
	static const quint32 magicFileMarker_;
	static const quint8 latestVersion_;

	const QString& filePath() const;
	const QString& filePathName() const;

public:
	/**
	 * @brief Determines if the exchange rates file exists.
	 *
	 * @return True when the cached path exists and is a file, false else-wise.
	 */
	bool exists() const;
	/**
	 * @brief Removes the cached exchange rate file.
	 */
	void remove() const;
	/**
	 * @brief Loads the exchange rates file.
	 *
	 * @exception BinaryFileError When the exchange rates file is not valid.
	 *
	 * @return The loaded exchange rates.
	 */
	drn::conversion::ConversionMap load() const;
	/**
	 * @brief Creates or overwrites the exchange rates file.
	 *
	 * @exception BinaryFileError When the exchange rates file cannot be saved.
	 *
	 * @param[in] cm The exchange rates whose contents are to be stored in the file.
	 */
	void store(const drn::conversion::ConversionMap& cm) const;
};

}}

#endif
