/*
 * Copyright (C) 2014-2021 CZ.NIC
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

#pragma once

#include <QMetaType>
#include <QScopedPointer>

class QString; /* Forward declaration. */

class TagEntryPrivate;
/*!
 * @brief Encapsulates database tag entry.
 */
class TagEntry {
	Q_DECLARE_PRIVATE(TagEntry)
public:
	TagEntry(void);
	TagEntry(const TagEntry &other);
#ifdef Q_COMPILER_RVALUE_REFS
	TagEntry(TagEntry &&other) Q_DECL_NOEXCEPT;
#endif /* Q_COMPILER_RVALUE_REFS */
	~TagEntry(void);

	TagEntry(int id, const QString &name, const QString &colour);
#ifdef Q_COMPILER_RVALUE_REFS
	TagEntry(int id, QString &&name, QString &&colour);
#endif /* Q_COMPILER_RVALUE_REFS */

	TagEntry &operator=(const TagEntry &other) Q_DECL_NOTHROW;
#ifdef Q_COMPILER_RVALUE_REFS
	TagEntry &operator=(TagEntry &&other) Q_DECL_NOTHROW;
#endif /* Q_COMPILER_RVALUE_REFS */

	bool operator==(const TagEntry &other) const;
	bool operator!=(const TagEntry &other) const;

	friend void swap(TagEntry &first, TagEntry &second) Q_DECL_NOTHROW;

	bool isNull(void) const;

	/*!
	 * @brief Check for validity.
	 *
	 * @note Invalid tag has negative id, empty name or bogus colour.
	 *
	 * @return True if tag contains valid data.
	 */
	bool isValid(void) const;

	int id(void) const;
	void setId(int i);

	const QString &name(void) const;
	void setName(const QString &n);
#ifdef Q_COMPILER_RVALUE_REFS
	void setName(QString &&n);
#endif /* Q_COMPILER_RVALUE_REFS */

	const QString &colour(void) const;
	void setColour(const QString &c);
#ifdef Q_COMPILER_RVALUE_REFS
	void setColour(QString &&c);
#endif /* Q_COMPILER_RVALUE_REFS */

	/*!
	 * @brief Returns true if colour string is valid.
	 *
	 * @param[in] colourStr Colour string.
	 * @return True if colour string is valid.
	 */
	static
	bool isValidColourStr(const QString &colourStr);

private:
	QScopedPointer<TagEntryPrivate> d_ptr; // ::std::unique_ptr ?
};

void swap(TagEntry &first, TagEntry &second) Q_DECL_NOTHROW;

/*!
 * @brief Return a hash value for the supplied tag entry.
 *
 * @param[in] entry Tag entry to compute hash from.
 * @param[in] seed Is used to initialise the hash if specified.
 * @return Hashed tag entry.
 */
uint qHash(const TagEntry &entry, uint seed = 0);

Q_DECLARE_METATYPE(TagEntry)
