#ifndef GELIB_IMPL_IO_H_
#define GELIB_IMPL_IO_H_

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <direct.h>

#include "Structures.h"

namespace gelib_impl
{

	namespace IO {
		/*
		 * file extension this class deals with
		 */
		const std::string FILE_EXTENSION = ".csv";

		using io_d_vector = std::vector<double>;
		using io_d_matrix = std::vector<io_d_vector>;

		/*
		 * Number of rows in the matrix
		 */
		size_t n_rows(io_d_matrix mat);

		/*
		 * Number of columns in a square matrix only
		 */
		size_t n_cols(io_d_matrix mat);

		void throw_on_input_error(const std::string& error);


		/*
		* Read in a matrix of doubles in comma-separated file format
		*/
		std::vector<std::vector<double>> read_matrix(std::string filename);

		/*
		 * Read in a matrix of doubles in comma-separated file format
		 * the first 'info_rows' rows will be pushed into the info vector
		 */
		std::vector<std::vector<double>> read_matrix(std::string filename, std::vector<std::vector<double>>& info, unsigned int info_rows = 0);

		/*
		 * write a matrix of doubles in comma-separated file format
		 */
		void write_matrix(std::string filename, std::vector<std::vector<double>> mat, std::ios_base::openmode = std::ofstream::out);

		/*
		 * Remove the file extension on a string containing a filename
		 */
		std::string remove_file_extension(std::string filename);

		/*
		 * insert the file extension used by this class
		 */
		std::string insert_file_extension(std::string filename);

		/*
		 * For debugging purposes - print an matrix to console
		 */
		void print_matrix(std::vector<std::vector<double>> mat);

		/*
		 * For debugging purposes - print an vector to console
		 */
		void print_vector(std::vector<double> const& v);

		/*
		 * For debugging purposes - print an array to console
		 */
		void print_array(const double* a, size_t size);

		/*
		* attempt to make a directory from given filename string and throw if it fails
		*/
		void mk_dir_safe(std::string dir_name);


	};

}

#endif /* IO_H_ */
