/**
 *  \brief     FreeCad  class.
 *  \details   Used to run FreeCAD
 *  \author    vadims
 *  \date      Jul 13, 2020
 *  \bug       Not all memory is freed when deleting an object of this class.
 *  \warning   Improper use can crash your application
 *  \copyright CENOS LLC
 */

#pragma once
#include <WinSock2.h>
#include <Windows.h>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <optional>
#include "Module.hpp"
#include "nlohmann/json.hpp"
#include "misc/messagedata.hpp"
#include "easylogging++/easylogging++.h"
#include "setup/SetupFactory.hpp"
#include "setup/Parameter.h"

using json = nlohmann::json;

class FreeCadModule : public Module {
public:
	FreeCadModule();
	~FreeCadModule();

	void setWDir(std::string);
	void setPort(int);
	void setGuid(std::string);
	void addCadFile(std::string);
	void setGeometryData(std::optional<json>);
	messagedata run();
	messagedata update();
	void stop();

private:
	std::string wDir;
	int port;
	std::string guid;
	bool stopRequired;
	std::vector<std::string> cadfiles;
	std::optional<json> geometryData;
	std::string createUpdateScript();
	void deleteFemTempFiles(std::string tempPath);
	messagedata executeFreeCad(std::string script, bool batchMode);


};
