#pragma once
// net module for MPFW
#include <iostream>
#include <vector>
#include <map>
#include <functional>


#define MPFW_NetCallback(x) void x(std::string packet, Socket* socket)

namespace MPFW {
	namespace Net {


		    // low-level operations for addresses, protocols, sockets, etc., 
		   // basically a raylib-compatible asio wrapper for windows compiling purposes.
		  // mpfw works on a system of relay servers and auth'd apps through an external
		 // auth server. these functions aren't going to be used very often outside of
		// predefined engine declarations.
		namespace System {



			struct Address {
				std::string ip; // human-readable internet address(domain name or internet protocol address(v4))
				int port;
			};

			using NetCallback = std::function<void >;
			enum SocketType {
				TCP, UDP
			};

			struct SocketInfo {
				SocketType type;
				Address address;
			};

			class Socket {
				SocketInfo info;
			public:
				Socket() {}
				Socket(SocketInfo __info) { Connect(__info); }

				void Connect(SocketInfo __info);

				std::function<void(std::string, Socket*)> connectCallback;
				std::function<void(std::string, Socket*)> receiveCallback;
				std::function<void(std::string, Socket*)> disconnectCallback;
				~Socket() {}
			};
		}

		namespace AppLevel {
			namespace Auth {
				struct UserInfo {
					std::string username, password;
				};
				class AuthServer {
				public:
					AuthServer() {}
					AuthServer(::MPFW::Net::System::Address address, UserInfo user) { ConnectToAuthServer(address, user); }

					void ConnectToAuthServer(::MPFW::Net::System::Address address, UserInfo user);

				};
			}
			class AppInterface {
			public:
				void Connect(::MPFW::Net::System::Address address, ::MPFW::Net::AppLevel::Auth::AuthServer auth);

			};
		}
	}
}