/*
 * Copyright (C) 2014-2026 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 <QByteArray>
#include <QList>
#include <QMetaType>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
#  include <memory> /* ::std::unique_ptr */
#else /* < Qt-5.12 */
#  include <QScopedPointer>
#endif /* >= Qt-5.12 */

#include "src/datovka_shared/isds/types.h"
#include "src/datovka_shared/json/object.h"

namespace Json {
	class NoteEntryList; /* Forward declaration. */
	class MsgId1List; /* Forward declaration. */
}

class QJsonValue; /* Forward declaration. */

namespace Json {

	class NoteAssignmentPrivate;
	/*!
	 * @brief Holds note assignment.
	 */
	class NoteAssignment : public Object {
		Q_DECLARE_PRIVATE(NoteAssignment)
	public:
		NoteAssignment(void);
		NoteAssignment(const NoteAssignment &other);
#ifdef Q_COMPILER_RVALUE_REFS
		NoteAssignment(NoteAssignment &&other) Q_DECL_NOEXCEPT;
#endif /* Q_COMPILER_RVALUE_REFS */
		~NoteAssignment(void);

		explicit NoteAssignment(enum Isds::Type::NilBool testEnv,
		    qint64 dmId, const NoteEntryList &entries);
#ifdef Q_COMPILER_RVALUE_REFS
		explicit NoteAssignment(enum Isds::Type::NilBool testEnv,
		    qint64 dmId, NoteEntryList &&entries);
#endif /* Q_COMPILER_RVALUE_REFS */

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

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

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

		bool isNull(void) const;

		bool isValid(void) const;

		/* test environment */
		enum Isds::Type::NilBool testEnv(void) const;
		void setTestEnv(enum Isds::Type::NilBool t);
		/* message identifier */
		qint64 dmId(void) const;
		void setDmId(qint64 di);
		/* entries */
		const NoteEntryList &entries(void) const;
		void setEntries(const NoteEntryList &l);
#ifdef Q_COMPILER_RVALUE_REFS
		void setEntries(NoteEntryList &&l);
#endif /* Q_COMPILER_RVALUE_REFS */

		static
		NoteAssignment fromJson(const QByteArray &json, bool *ok = Q_NULLPTR);
		static
		NoteAssignment fromJsonVal(const QJsonValue &jsonVal, bool *ok = Q_NULLPTR);

		virtual
		bool toJsonVal(QJsonValue &jsonVal) const Q_DECL_OVERRIDE;

	private:
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
		::std::unique_ptr<NoteAssignmentPrivate> d_ptr;
#else /* < Qt-5.12 */
		QScopedPointer<NoteAssignmentPrivate> d_ptr;
#endif /* >= Qt-5.12 */
	};

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

	/*!
	 * @brief List of note assignments.
	 */
	class NoteAssignmentList : public Object, public QList<NoteAssignment> {
	public:
		/* Expose list constructors. */
		using QList<NoteAssignment>::QList;

		/* Some older compilers complain about missing constructor. */
		NoteAssignmentList(void);

		NoteAssignmentList(const QList<NoteAssignment> &other);
#ifdef Q_COMPILER_RVALUE_REFS
		NoteAssignmentList(QList<NoteAssignment> &&other);
#endif /* Q_COMPILER_RVALUE_REFS */

		static
		NoteAssignmentList fromJson(const QByteArray &json, bool *ok = Q_NULLPTR);
		static
		NoteAssignmentList fromJsonVal(const QJsonValue &jsonVal, bool *ok = Q_NULLPTR);

		virtual
		bool toJsonVal(QJsonValue &jsonVal) const Q_DECL_OVERRIDE;
	};

}

Q_DECLARE_METATYPE(Json::NoteAssignment)
Q_DECLARE_METATYPE(Json::NoteAssignmentList)
