#pragma once

#include <Base_Packet.h>
#include <fstream>
#include <nlohmann/json.hpp>

using namespace nlohmann;

namespace inaf::oasbo::Packets {

/**
 * @brief Represents a JSON packet structure for ASTRI DAQ.
 * 
 * This class extends the BasePacketStructure class and provides functionality
 * to convert JSON data into a tuple vector and read the structure from a source.
 * The compatible json files are in config folder.
 */
class PacketStructureJson: public inaf::oasbo::Packets::BasePacketStructure {

protected:
	/**
	 * @brief Converts JSON data into a tuple vector.
	 * 
	 * @param data The JSON data to convert.
	 * @param count The count of tuples in the vector.
	 * @return An optional structure representing the tuple vector.
	 */
	static std::optional<Structure> convertToTupleVector(const ordered_json &data,
			uint &count);

	/**
	 * @brief Reads the packet structure from a source.
	 * 
	 * @param source The source from which to read the structure.
	 * @return The structure read from the source.
	 */
	static Structure readStructureFromSource(std::string source);

public:
	/**
	 * @brief Constructs a PacketStructureJson object with the specified source.
	 * 
	 * @param source The source from which to read the structure.
	 */
	PacketStructureJson(std::string source) :
			BasePacketStructure(source, &readStructureFromSource) {
	}

	/**
	 * @brief Constructs a PacketStructureJson object from another BasePacketStructure object.
	 * 
	 * @param other The BasePacketStructure object to copy from.
	 */
	PacketStructureJson(const BasePacketStructure &other) :
			BasePacketStructure(other) {
	}
};
}