
#include <iostream>
#include <exception>
#include <stdexcept>
#include "Webserv.hpp"
#include "ConfigParser.hpp"

int	main(int ac, char **av)
{
	std::vector<ServerConfig>* servers_config = NULL;
	try
	{
		std::string	config = (ac == 2 ? av[1] : "./default.config");

		ConfigParser	configParser(config);
		// configParser.print_content();

		// i don't love that servers_config has to be a pointer...
		servers_config = configParser.parse();
		
	// use an iterator you moron
		for (std::vector<ServerConfig>::iterator it = servers_config->begin(); it < servers_config->end(); it++)
		{
			(void)0;
	//		std::cout << it->server_name << " ";
	//		 it->print_all();
		}


//		Webserv	serv(configParser.parse());
	// is this better or worse than using 

		Webserv	serv;

		// serv.init_virtual_servers();
		serv.init_virtual_servers(servers_config);
		delete servers_config;
		servers_config = NULL;
		serv.run();
	}
	catch (std::exception& e)
	{
		std::cerr << e.what() << '\n';
		delete servers_config;
	}

	return (0);
}
