#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <filesystem>
#include <unistd.h>

#if defined(_WIN32) || defined(_WIN64)
#	include <conio.h>
#endif

namespace System {
	using namespace std;
	namespace fs = filesystem;
	
	namespace ConsoleFunctions {
		void ClearConsole() {
			#if defined(_WIN32) || defined(_WIN64)
				system("cls");
			#else
				system("clear");
			#endif
		}
		
		#if defined(_WIN32) || defined(_WIN64)
		int getkey() {
			int ch = 0;
			if (_kbhit())
				ch = _getch();
			return ch;
		}
		#endif
		
		
	}
	
	class Users {
		public:
			enum UserType {
				SuperUser = 0,
				NormalUser = 1,
				Guest = 2
			};
		
			struct User {
				string name;
				string password;
				UserType type;
				
				User(const string& n, const string& p, const UserType& t) {
					name = n;
					password = p;
					type = t;
				}
			};
			
		protected:
			unordered_map <string, User> UserDB;
			User current;
			
		public:
			bool UserAdd(const string& n, const string& p, const UserType& t = NormalUser) {
				if (UserDB.count(n) == 0) {
					cerr << "UserAdd: User " << n << "Already Exists." << endl;
					return false;
				} else {
					UserDB[n] = User(n, p, t);
					return true;
				}
			}
			
			void init() {
				UserDB.clear();
				UserAdd("root", "password", SuperUser);
			}
			
			bool try_login(const string& name, const string& password) {
				if (UserDB.count(name) && UserDB[name].password == password) {
					current = UserDB[name];
					cout << "Welcome " << current.name << '.' << endl;
					return true;
				} else {
					cout << "Wrong password for user " << name << '.' << endl;
					return false;
				}
			}
			
			User current_login() {
				return current;
			}
	};
	
	void run() {
		cout << "Welcome to nPrSystem!" << endl;
		
		string name;
		cin >> name;
		
	}
	
}