#include "utilites.h"

#include <vector>
#include <QTextStream>
#include <QFile>
#include <QDebug>
#include <QStringList>
#include <QMessageBox>
#include <thread>
#include <stdexcept>

bool saveToCsv(const QString& filename, const std::vector<double> &keys, const std::vector<double> &values, const QString& keyLable, const QString& valueLable )
{
	if(keys.size() != values.size())
	{
		throw std::invalid_argument("keys and values need to be the same size");
		return false;
	}
	QFile file(filename);
	if(file.open(QIODevice::WriteOnly | QIODevice::Text))
	{
		QTextStream fileStream(&file);
		fileStream<<"id"<<','<<keyLable<<','<<valueLable<<'\n';
		for(size_t i = 0; i < keys.size(); i++)
		{
			fileStream<<i<<','<<(int64_t)keys[i]<<','<<values[i]<<'\n';
		}
		fileStream.flush();
		file.close();
		return true;
	}
	return false;
}
