#ifndef DIFFRACTIONGRATING_HPP_INCLUDED
#define DIFFRACTIONGRATING_HPP_INCLUDED

#include <iostream>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include <NBO/NBO/ModulationModeList_Type.h>
#include <NBO/NBO/OpticalAperture_Type.h>
#include <NBO/NBO/UnitsLength_Type.h>
#include <NBO/NBO/ENBOType.h>
#include <NBO/NBOGlobal.h>
#include <NBO/Shared/Base/NBOBaseClass.h>


namespace Inscoper::NBO {

/*!
* \brief Represents the XML element DiffractionGrating.
*
* A Diffraction Grating is an optical component with a periodic structure that splits and diffracts light into several beams travelling in different directions.
*/
class NBO_EXPORT DiffractionGrating : public OpticalAperture_Type {

public:
	
	DiffractionGrating();
	~DiffractionGrating();

	/*!
	* \brief Cast a NBOBaseClass to a DiffractionGrating.
	*
	* \param base The base class to cast
	* \return The casted element, or nullptr if the cast fails
	*/
	static std::shared_ptr<DiffractionGrating> 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 Period attribute.
	*
	* This field records the spacing between the centers of two adjacent slits (d).
	*
	* \param value The value to set
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setPeriod(const float& value, bool validate = true);

	/*!
	* \brief Returns the value of the Period attribute.
	*
	* This field records the spacing between the centers of two adjacent slits (d).
	*
	* \return The value of the attribute
	*/
	float getPeriod() const;

	/*!
	* \brief Resets the Period attribute to an unset state.
	*
	* This field records the spacing between the centers of two adjacent slits (d).
	*/
	void resetPeriod();

	/*!
	* \brief Checks whether the Period attribute is present.
	*
	* This field records the spacing between the centers of two adjacent slits (d).
	*
	* \return true if the attribute has been set, false otherwise
	*/
	bool hasPeriod() const;

	/*!
	* \brief Sets the value of the PeriodUnit 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 setPeriodUnit(const Inscoper::NBO::UnitsLength_TypePtr& value, bool validate = true);

	/*!
	* \brief Returns the value of the PeriodUnit attribute.
	*
	* No description available in the XSD standard.
	*
	* \return The value of the attribute
	*/
	UnitsLength_TypePtr getPeriodUnit() const;

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

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

	/*!
	* \brief Sets the value of the SpatialFrequency attribute.
	*
	* This field records the number of slits (or lines) per unit length (1/d). Typically it is measured in terms of number of slits per millimiter.
	*
	* \param value The value to set
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setSpatialFrequency(const float& value, bool validate = true);

	/*!
	* \brief Returns the value of the SpatialFrequency attribute.
	*
	* This field records the number of slits (or lines) per unit length (1/d). Typically it is measured in terms of number of slits per millimiter.
	*
	* \return The value of the attribute
	*/
	float getSpatialFrequency() const;

	/*!
	* \brief Resets the SpatialFrequency attribute to an unset state.
	*
	* This field records the number of slits (or lines) per unit length (1/d). Typically it is measured in terms of number of slits per millimiter.
	*/
	void resetSpatialFrequency();

	/*!
	* \brief Checks whether the SpatialFrequency attribute is present.
	*
	* This field records the number of slits (or lines) per unit length (1/d). Typically it is measured in terms of number of slits per millimiter.
	*
	* \return true if the attribute has been set, false otherwise
	*/
	bool hasSpatialFrequency() const;

	/*!
	* \brief Sets the value of the Transmittive attribute.
	*
	* This field records whether the periodic fine structure of this Diffraction Grating is Transmissive (True) and therefore refracts light, or is Reflective (False) and therefore reflects it.
	*
	* \param value The value to set
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setTransmittive(const bool& value, bool validate = true);

	/*!
	* \brief Returns the value of the Transmittive attribute.
	*
	* This field records whether the periodic fine structure of this Diffraction Grating is Transmissive (True) and therefore refracts light, or is Reflective (False) and therefore reflects it.
	*
	* \return The value of the attribute
	*/
	bool getTransmittive() const;

	/*!
	* \brief Resets the Transmittive attribute to an unset state.
	*
	* This field records whether the periodic fine structure of this Diffraction Grating is Transmissive (True) and therefore refracts light, or is Reflective (False) and therefore reflects it.
	*/
	void resetTransmittive();

	/*!
	* \brief Checks whether the Transmittive attribute is present.
	*
	* This field records whether the periodic fine structure of this Diffraction Grating is Transmissive (True) and therefore refracts light, or is Reflective (False) and therefore reflects it.
	*
	* \return true if the attribute has been set, false otherwise
	*/
	bool hasTransmittive() const;

	/*!
	* \brief Sets the value of the ModulationMode attribute.
	*
	* This field indicates what aspect of the light beam is modulated by this device.
	*
	* \param value The value to set
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setModulationMode(const Inscoper::NBO::ModulationModeList_TypePtr& value, bool validate = true);

	/*!
	* \brief Returns the value of the ModulationMode attribute.
	*
	* This field indicates what aspect of the light beam is modulated by this device.
	*
	* \return The value of the attribute
	*/
	ModulationModeList_TypePtr getModulationMode() const;

	/*!
	* \brief Resets the ModulationMode attribute to an unset state.
	*
	* This field indicates what aspect of the light beam is modulated by this device.
	*/
	void resetModulationMode();

	/*!
	* \brief Checks whether the optional ModulationMode attribute is present.
	*
	* This field indicates what aspect of the light beam is modulated by this device.
	*
	* \return true if the optional attribute has been set, false otherwise
	*/
	bool hasModulationMode() const;

	/*!
	* \brief Sets the value of the Ronchi attribute.
	*
	* This field records whether this Diffraction Grating has a square wave profile, as defined by Ronchi (True) or a sine wave profile (False).
	*
	* \param value The value to set
	* \param validate If true, validates constraints on value. Default is true.
	*/
	void setRonchi(const bool& value, bool validate = true);

	/*!
	* \brief Returns the value of the Ronchi attribute.
	*
	* This field records whether this Diffraction Grating has a square wave profile, as defined by Ronchi (True) or a sine wave profile (False).
	*
	* \return The value of the attribute
	*/
	bool getRonchi() const;

	/*!
	* \brief Resets the Ronchi attribute to an unset state.
	*
	* This field records whether this Diffraction Grating has a square wave profile, as defined by Ronchi (True) or a sine wave profile (False).
	*/
	void resetRonchi();

	/*!
	* \brief Checks whether the Ronchi attribute is present.
	*
	* This field records whether this Diffraction Grating has a square wave profile, as defined by Ronchi (True) or a sine wave profile (False).
	*
	* \return true if the attribute has been set, false otherwise
	*/
	bool hasRonchi() const;


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

    std::optional<float> Period; // Required attribute
	UnitsLength_TypePtr PeriodUnit = nullptr; // Optional attribute
    std::optional<float> SpatialFrequency; // Required attribute
    std::optional<bool> Transmittive; // Optional attribute
	ModulationModeList_TypePtr ModulationMode = nullptr; // Optional attribute
    std::optional<bool> Ronchi; // Optional attribute
};

/*! Shared pointer for DiffractionGrating*/
typedef std::shared_ptr<DiffractionGrating> DiffractionGratingPtr;

} // namespace Inscoper::NBO

#endif // DIFFRACTIONGRATING_HPP_INCLUDED