#ifndef WIDGETS_GRAPHPLOTTER_DATASET_IO_H
#define WIDGETS_GRAPHPLOTTER_DATASET_IO_H

#include "DataSet.h"
#include "Interpolator.h"


// -- TDE NAMESPACE ----------------------------------------------------

namespace TDE {

// -- Widgets NAMESPACE ------------------------------------------------

namespace Widgets {

namespace Plot {

/*!
 * \namespace TDE::Widgets::Plot::DataSetIO
 * \brief Namespace for DataSet I/O
 *
 * Functions and classes for DataSet IO are contained in this namespace.
 */

namespace DataSetIO {

// load a DataSet from CSV (creating it)
DataSetPtr LoadCSV(
	const std::string& pathname,
	const std::string& name, const QColor& fg = Qt::lightGray, DataSet::Kind kind = DataSet::DATA, const InterpolatorParameters& params = InterpolatorParameters(),
	bool headerLine = true, bool do_emit = true);

// load a DataSet from CSV (overwriting its contents)
bool LoadCSV(DataSetPtr dataSetPtr, const std::string& pathname, bool headerLine = true, bool do_emit = true);
bool LoadCSV(DataSet& dataSet, const std::string& pathname, bool headerLine = true, bool do_emit = true);

// save a DataSet to CSV
bool SaveCSV(DataSetPtr dataSetPtr, const std::string& pathname, bool headerLine = true, bool inViewport = false, bool interpolated = false, int nPoints = -1, double width = -1);
bool SaveCSV(const DataSet& dataSet, const std::string& pathname, bool headerLine = true, bool inViewport = false, bool interpolated = false, int nPoints = -1, double width = -1);

// load multiple distinct CSV files in one go
bool LoadDistinctCSVs(
	std::vector<DataSetPtr>& loaded,
	const std::vector<std::string>& pathnames,
	F_FUNCTION<bool (const std::string&)> filterCallback = 0,
	F_FUNCTION<void (const std::string& pathname, std::string& name, QColor& fg, DataSet::Kind& kind, InterpolatorParameters& params)> propertiesCallback = 0,
	F_FUNCTION<void (const std::string&, DataSetPtr)> loadedCallback = 0,
	bool headerLine = true, bool do_emit = true);

// save multiple distinct CSV files in one go
bool SaveDistinctCSVs(
	const std::vector<DataSetPtr>& datasets,
	F_FUNCTION<std::string (DataSetPtr, int)> pathnameCallback,
	F_FUNCTION<bool (const std::string& pathname, DataSetPtr)> filterCallback = 0,
	bool headerLine = true, bool inViewport = false, bool interpolated = false, int nPoints = -1, double width = -1);

// save many datasets to a single CSV
bool SaveManySingleCSV(
	const std::string& pathname,
	const std::vector<DataSetPtr>& datasets,
	F_FUNCTION<bool (DataSetPtr)> filterCallback = 0,
	bool headerLine = true, bool inViewport = false, bool interpolated = false, int nPoints = -1, double width = -1);

// load many datasets from a single CSV
bool LoadManySingleCSV(
	std::vector<DataSetPtr>& loaded,
	const std::string& pathname,
	F_FUNCTION<void (const std::string& pathname, int index, std::string& name, QColor& fg, DataSet::Kind& kind, InterpolatorParameters& params)> propertiesCallback = 0,
	F_FUNCTION<void (int index, DataSetPtr)> loadedCallback = 0,
	bool headerLine = true, bool do_emit = true);


} /* end of namespace DataSetIO */

} /* end of namespace Plot */

} /* end of namespace Widgets */

} /* end of namespace TDE */

#endif /* WIDGETS_GRAPHPLOTTER_DATASET_IO_H */
