#ifndef FOLDER_HPP_INCLUDED
#define FOLDER_HPP_INCLUDED

#include <iostream>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include <NBO/NBO/AnnotationRef.h>
#include <NBO/NBO/FolderID_Type.h>
#include <NBO/NBO/FolderRef.h>
#include <NBO/NBO/ImageRef.h>
#include <NBO/NBO/ROIRef.h>
#include <NBO/NBO/ENBOType.h>
#include <NBO/NBOGlobal.h>
#include <NBO/Shared/Base/NBOBaseClass.h>


namespace Inscoper::NBO {

/*!
* \brief Represents the XML element Folder.
*
* An element specifying a possibly heterogeneous collection of data. Folders may contain Folders so that data may be organized within a tree of Folders. Data may be in multiple Folders but a Folder may not be in more than one other Folder. 
*/
class NBO_EXPORT Folder : public NBOBaseClass {

public:
	/*!
	* \brief Represents the XML element Description.
	*
	* No description available in the XSD standard.
	*/
	class NBO_EXPORT InlineDescription : public NBOBaseClass {
	
	public:
		
		InlineDescription();
		~InlineDescription();
	
		/*!
		* \brief Cast a NBOBaseClass to a InlineDescription.
		*
		* \param base The base class to cast
		* \return The casted element, or nullptr if the cast fails
		*/
		static std::shared_ptr<InlineDescription> fromBase(NBOBaseClassPtr base);
	
		/*!
		* \brief Returns the class type name.
		*
		* \return The class type name
		*/
		std::string getTypeName() const override;
	
		/*!
		* \brief Returns the XML element name corresponding to this class.
		*
		* \return The XML element name
		*/
		std::string getXMLName() const override;
	
		/*!
		* \brief Returns the NBO Type corresponding to this class.
		*
		* \return The NBO Type value
		*/
		ENBOType getNBOType() const override;
	
		/*!
		* \brief Returns a list of all classes derived from this class.
		*
		* \return The list of derived classes
		*/
		std::vector<NBOBaseClassPtr> getChildren() const override;
	
		/*!
		* \brief Returns a list of all child elements contained in this class.
		*
		* \return The list of child classes
		*/
		std::vector<NBOBaseClassPtr> getSubElements() const override;
	
		/*!
		* \brief Populates this object from a JSON file.
		*
		* \param path The path to the JSON file
		* \param validate If true, validates constraints on value. Default is true.
		*/
		void fromJsonFile(const std::string& path, bool validate = true);
	
		/*!
		* \brief Populates this object from a JSON string.
		*
		* \param json_string The JSON content as a string
		* \param validate If true, validates constraints on value. Default is true.
		*/
		void fromJsonString(const std::string& json_string, bool validate = true);
	
		/*!
		* \brief Populates this object from a XML file.
		*
		* \param path The path to the XML file
		* \param validate If true, validates constraints on value. Default is true.
		*/
		void fromXmlFile(const std::string& path, bool validate = true);
	
		/*!
		* \brief Populates this object from a XML string.
		*
		* \param xml_string The XML content as a string
		* \param validate If true, validates constraints on value. Default is true.
		*/
		void fromXmlString(const std::string& xml_string, bool validate = true);
	
		/*!
		* \brief Serializes this object to an XML file.
		*
		* \param filename The path to the output XML file
		* \param validate If true, validates constraints on value. Default is true.
		*/
		void toXmlFile(const std::string& filename, bool validate = true) const;
	
		/*!
		* \brief Serializes this object to an XML string.
		*
		* \param validate If true, validates constraints on value. Default is true.
		* \return A string containing the XML representation of this object
		*/
		std::string toXmlString(bool validate = true) const;
	
		/*!
		* \brief Assigns a new value to this object (= operator operator).
		*
		* \param v The value to set
		*/
		InlineDescription& operator=(const std::string& v);
	
		/*!
		* \brief Returns the value of this object  (generic conversion operator overload).
		*
		* \return The value of the object
		*/
		operator std::string() const;
	
		/*!
		* \brief Assigns a new value to this object.
		*
		* \param v The value to set
		* \param validate If true, validates constraints on value. Default is true.
		*/
		void set(const std::string& v, bool validate = true);
	
		/*!
		* \brief Returns the value of this object.
		*
		* \return The value of the object
		*/
		std::string get() const;
	
		/*!
		* \brief Returns the allowed values for this object.
		*
		* \return The list of allowed values
		*/
		static const std::set<std::string>& getAllowedValues();
	
		/*!
		* \brief Returns the pattern for this object.
		*
		* \return The pattern
		*/
		static const std::string& getPattern();
	
	private:
		std::string value;
	
		static const std::set<std::string> allowedValues;
		static const std::string validationPattern;
		friend std::ostream& operator<<(std::ostream& os, const InlineDescription& u);
	
	
	private:
		class Impl;
		std::unique_ptr<Impl> pImpl;
	};
	
	/*! Shared pointer for InlineDescription*/
	typedef std::shared_ptr<InlineDescription> InlineDescriptionPtr;
	
	
	Folder();
	~Folder();

	/*!
	* \brief Cast a NBOBaseClass to a Folder.
	*
	* \param base The base class to cast
	* \return The casted element, or nullptr if the cast fails
	*/
	static std::shared_ptr<Folder> fromBase(NBOBaseClassPtr base);

	/*!
	* \brief Returns the class type name.
	*
	* \return The class type name
	*/
	std::string getTypeName() const override;

	/*!
	* \brief Returns the XML element name corresponding to this class.
	*
	* \return The XML element name
	*/
	std::string getXMLName() const override;

	/*!
	* \brief Returns the NBO Type corresponding to this class.
	*
	* \return The NBO Type value
	*/
	ENBOType getNBOType() const override;

	/*!
	* \brief Returns a list of all classes derived from this class.
	*
	* \return The list of derived classes
	*/
	std::vector<NBOBaseClassPtr> getChildren() const override;

	/*!
	* \brief Returns a list of all child elements contained in this class.
	*
	* \return The list of child classes
	*/
	std::vector<NBOBaseClassPtr> getSubElements() const override;

	/*!
	* \brief Populates this object from a JSON file.
	*
	* \param path The path to the JSON file
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void fromJsonFile(const std::string& path, bool validate = true);

	/*!
	* \brief Populates this object from a JSON string.
	*
	* \param json_string The JSON content as a string
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void fromJsonString(const std::string& json_string, bool validate = true);

	/*!
	* \brief Populates this object from a XML file.
	*
	* \param path The path to the XML file
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void fromXmlFile(const std::string& path, bool validate = true);

	/*!
	* \brief Populates this object from a XML string.
	*
	* \param xml_string The XML content as a string
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void fromXmlString(const std::string& xml_string, bool validate = true);

	/*!
	* \brief Serializes this object to an XML file.
	*
	* \param filename The path to the output XML file
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void toXmlFile(const std::string& filename, bool validate = true) const;

	/*!
	* \brief Serializes this object to an XML string.
	*
	* \param validate If true, validates constraints on value. Default is true.
	* \return A string containing the XML representation of this object
	*/
	std::string toXmlString(bool validate = true) const;

	/*!
	* \brief Sets the value of the ID attribute.
	*
	* No description available in the XSD standard.
	*
	* \param value The value to set
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setID(const Inscoper::NBO::FolderID_TypePtr& value, bool validate = true);

	/*!
	* \brief Returns the value of the ID attribute.
	*
	* No description available in the XSD standard.
	*
	* \return The value of the attribute
	*/
	FolderID_TypePtr getID() const;

	/*!
	* \brief Resets the ID attribute to an unset state.
	*
	* No description available in the XSD standard.
	*/
	void resetID();

	/*!
	* \brief Checks whether the optional ID attribute is present.
	*
	* No description available in the XSD standard.
	*
	* \return true if the optional attribute has been set, false otherwise
	*/
	bool hasID() const;

	/*!
	* \brief Sets the value of the Name attribute.
	*
	* A name for the folder that is suitable for presentation to the user. 
	*
	* \param value The value to set
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setName(const std::string& value, bool validate = true);

	/*!
	* \brief Returns the value of the Name attribute.
	*
	* A name for the folder that is suitable for presentation to the user. 
	*
	* \return The value of the attribute
	*/
	std::string getName() const;

	/*!
	* \brief Resets the Name attribute to an unset state.
	*
	* A name for the folder that is suitable for presentation to the user. 
	*/
	void resetName();

	/*!
	* \brief Checks whether the Name attribute is present.
	*
	* A name for the folder that is suitable for presentation to the user. 
	*
	* \return true if the attribute has been set, false otherwise
	*/
	bool hasName() const;

	/*!
	* \brief Returns the allowed values for this attribut.
	*
	* A name for the folder that is suitable for presentation to the user. 
	*
	* \return The list of allowed values
	*/
	static const std::set<std::string>& getNameAllowedValues();

	/*!
	* \brief Sets the value of the Description element.
	*
	* A description for the folder. [plain-text multi-line string] 
	*
	* \param value The value to set
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setDescription(const Inscoper::NBO::Folder::InlineDescriptionPtr& value, bool validate = true);

	/*!
	* \brief Returns the value of the Description element.
	*
	* A description for the folder. [plain-text multi-line string] 
	*
	* \return The value of the element
	*/
	Inscoper::NBO::Folder::InlineDescriptionPtr getDescription() const;

	/*!
	* \brief Resets the Description element to an unset state.
	*
	* A description for the folder. [plain-text multi-line string] 
	*/
	void resetDescription();

	/*!
	* \brief Checks whether the optional Description element is present.
	*
	* A description for the folder. [plain-text multi-line string] 
	*
	* \return true if the optional attribute has been set, false otherwise
	*/
	bool hasDescription() const;

	/*!
	* \brief Sets the list of FolderRef elements.
	*
	* No description available in the XSD standard.
	*
	* \param value The new list of FolderRef elements
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setFolderRef_List(const std::vector<Inscoper::NBO::FolderRefPtr>& value, bool validate = true);

	/*!
	* \brief Returns the list of FolderRef elements.
	*
	* No description available in the XSD standard.
	*
	* \return The list of FolderRef elements
	*/
	std::vector<Inscoper::NBO::FolderRefPtr> getFolderRef_List() const;

	/*!
	* \brief Adds a new FolderRef element to this object.
	*
	* No description available in the XSD standard.
	*
	* \param value The element to add
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void addToFolderRef_List(const Inscoper::NBO::FolderRefPtr& value, bool validate = true);

	/*!
	* \brief Clear the list of FolderRef.
	*
	* No description available in the XSD standard.
	*/
	void clearFolderRef_List();

	/*!
	* \brief Sets the list of ImageRef elements.
	*
	* No description available in the XSD standard.
	*
	* \param value The new list of ImageRef elements
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setImageRef_List(const std::vector<Inscoper::NBO::ImageRefPtr>& value, bool validate = true);

	/*!
	* \brief Returns the list of ImageRef elements.
	*
	* No description available in the XSD standard.
	*
	* \return The list of ImageRef elements
	*/
	std::vector<Inscoper::NBO::ImageRefPtr> getImageRef_List() const;

	/*!
	* \brief Adds a new ImageRef element to this object.
	*
	* No description available in the XSD standard.
	*
	* \param value The element to add
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void addToImageRef_List(const Inscoper::NBO::ImageRefPtr& value, bool validate = true);

	/*!
	* \brief Clear the list of ImageRef.
	*
	* No description available in the XSD standard.
	*/
	void clearImageRef_List();

	/*!
	* \brief Sets the list of ROIRef elements.
	*
	* No description available in the XSD standard.
	*
	* \param value The new list of ROIRef elements
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setROIRef_List(const std::vector<Inscoper::NBO::ROIRefPtr>& value, bool validate = true);

	/*!
	* \brief Returns the list of ROIRef elements.
	*
	* No description available in the XSD standard.
	*
	* \return The list of ROIRef elements
	*/
	std::vector<Inscoper::NBO::ROIRefPtr> getROIRef_List() const;

	/*!
	* \brief Adds a new ROIRef element to this object.
	*
	* No description available in the XSD standard.
	*
	* \param value The element to add
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void addToROIRef_List(const Inscoper::NBO::ROIRefPtr& value, bool validate = true);

	/*!
	* \brief Clear the list of ROIRef.
	*
	* No description available in the XSD standard.
	*/
	void clearROIRef_List();

	/*!
	* \brief Sets the list of AnnotationRef elements.
	*
	* No description available in the XSD standard.
	*
	* \param value The new list of AnnotationRef elements
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setAnnotationRef_List(const std::vector<Inscoper::NBO::AnnotationRefPtr>& value, bool validate = true);

	/*!
	* \brief Returns the list of AnnotationRef elements.
	*
	* No description available in the XSD standard.
	*
	* \return The list of AnnotationRef elements
	*/
	std::vector<Inscoper::NBO::AnnotationRefPtr> getAnnotationRef_List() const;

	/*!
	* \brief Adds a new AnnotationRef element to this object.
	*
	* No description available in the XSD standard.
	*
	* \param value The element to add
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void addToAnnotationRef_List(const Inscoper::NBO::AnnotationRefPtr& value, bool validate = true);

	/*!
	* \brief Clear the list of AnnotationRef.
	*
	* No description available in the XSD standard.
	*/
	void clearAnnotationRef_List();


private:
	class Impl;
	std::unique_ptr<Impl> pImpl;

	FolderID_TypePtr ID = nullptr; // Required attribute
    std::optional<std::string> Name; // Optional attribute
    static const std::set<std::string> NameAllowedValues;
    Inscoper::NBO::Folder::InlineDescriptionPtr Description = nullptr;
    std::vector<Inscoper::NBO::FolderRefPtr> FolderRef_List;
    std::vector<Inscoper::NBO::ImageRefPtr> ImageRef_List;
    std::vector<Inscoper::NBO::ROIRefPtr> ROIRef_List;
    std::vector<Inscoper::NBO::AnnotationRefPtr> AnnotationRef_List;
};

/*! Shared pointer for Folder*/
typedef std::shared_ptr<Folder> FolderPtr;

} // namespace Inscoper::NBO

#endif // FOLDER_HPP_INCLUDED