#include <string>
#include <fstream>
#include <iostream>

using namespace std;

int multiply(int a, int b) { // Multiplies items for the shopping basket
	return a * b;
}

int addUp(int a, int b) { // Adds items for the shopping basket
	return a + b;
}

int main() {

	const int userMaxCount = 10; // Defines the maximum amount of users that can use the program at once.
	while (userMaxCount > 11) { // While over the limit, forces users to exit
		cout << "We're sorry, we are currently experiencing high levels of traffic. Please try again later.";
		exit;
	};
	int i = 0;

	class bankingDetails {
	public:
		bankingDetails(int& username, int& password, int& accountID, string& price) {
			int bankNum = 1111222233334444;
			int sortCode = 55555555; // User banking details
			int secNum = 666;
			string cardName = "John Johnson";
		}
	};

	int login(); { // startup

		int startup;
		while (true) {
			cout << "Welcome to the shopping app. Press 1 to login, or 2 to exit the program. " << endl;
			cin >> startup; // User enters input
			if (startup == 1) { // If input = 1 break the loop
				cout << "Loading login... " << endl;
				break;
			}
			else if (startup == 2) { // If input = 2 exit the program
				cout << "Exiting program... " << endl;
				exit;
				return 0;
			}
			else { // If input does not = 1 or 2, loop
				cout << "That input is invalid. Please try again. " << endl;
			}
		}

	}

	int userData(); { 

		// login

		string username[userMaxCount]; // Creating username array

		username[0] = { "1" };
		username[1] = { "username2" }; // Usernames 
		username[2] = { "username" };

		string password[userMaxCount]; // Creating password array

		password[0] = { "1" };
		password[1] = { "password2" }; // Passwords
		password[2] = { "password" };

		string enteredUsername; // Stores entered username and password
		string enteredPassword;



		bool userFound = false; // Checking if username and password are correct; default set to false
		while (userFound == false) {
			cout << "Enter your username now: " << endl;
			cin >> enteredUsername; // User enters username

			cout << "Enter your password now: " << endl;
			cin >> enteredPassword; // User enters password



			if (username[i] == enteredUsername && password[i] == enteredPassword) { // If both username and password are correct
				userFound = true; // The user has been found; userFound is true
				cout << "You have successfully logged in." << endl;
				break;
			}
			else {
				cout << "User not found. Please try again." << endl; // User is not found; loops
			}
		}

		int basket(); { // Creating the basket

			// main

			cout << "Welcome to the shop interface. Please select an option to continue." << endl;

			int userInput = 0; // User inputs for section screens
			int userInputMain = 0; // User input for main screen
			int userInputItem = 0; // User inputs for individual items
			int userInputAmount; // For how many of an item they want
			bool programDone = false;
			bool userExit = false; // For exit

			// Creating variables for totals; this is for the checkout later
			int milkTotal = 0;
			int cheeseTotal = 0;
			int cCheeseTotal = 0;
			int sCheeseTotal = 0;

			int wBreadTotal = 0;
			int bBreadTotal = 0;
			int doughnutTotal = 0;
			int cookieTotal = 0;

			int tSoupTotal = 0;
			int spamTotal = 0;
			int cTunaTotal = 0;

			int tShirtTotal = 0;
			int trousersTotal = 0;
			int coatTotal = 0;
			int shoesTotal = 0;

			class itemInfo { // Basic class for item details; used by derived classes as a base to build from
			public:
				int value;
				int quantity;
			};

			while (userInputMain == 0) {


				cout << "1. Dairy" << endl << "2. Bakery" << endl << "3. Canned Goods" << endl << "4. Clothing products" << endl << "5. Checkout" << endl << "6. Exit" << endl;
				cin >> userInputMain;

				while (userInputMain == 1) { // Go to Dairy products

					class dairy : public itemInfo { // Creating derived class dairy from itemInfo
					public:
						string milkQuantity;
					};

					cout << "Welcome to the dairy section." << endl << "1. Milk - £2" << endl << "2. Cheese - £3" << endl << "3. Cream Cheese - £2" << endl << "4. Sliced Cheese - £1" << endl;


					cin >> userInput;

					if (userInput == 1) {
						dairy milk; // Defines milk using itemInfo class; creating a milk object
						milk.value = 2; // Price of item
						milk.quantity = 0; // Items wanted by customer default to 0
						milk.milkQuantity = "99%"; // % of milk in item
						cout << "Milk - " << milk.milkQuantity << " Milk - £2" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						milk.quantity = userInputItem; // Sets the quantity to user entered amount
						milkTotal = multiply(milk.value, milk.quantity); // Multiply function to multiply milk cost by quantity
						cout << "That comes to £" << milkTotal << endl;
					}

					if (userInput == 2) {
						dairy cheese; // Defines cheese using itemInfo class; creating a cheese object
						cheese.value = 3; // Price of item
						cheese.quantity = 0; // Items wanted by customer default to 0
						cheese.milkQuantity = "40%"; // % of milk in item
						cout << "Cheese - " << cheese.milkQuantity << " Milk -  £3" << cheese.value << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						cheese.quantity = userInputItem; // Sets the quantity to user entered amount
						cheeseTotal = multiply(cheese.value, cheese.quantity); // Multiply function to multiply cheese cost by quantity
						cout << "That comes to £" << cheeseTotal << endl;
					}

					if (userInput == 3) {
						dairy cCheese; // Defines cream cheese using itemInfo class; creating a cCheese object
						cCheese.value = 2; // Price of item
						cCheese.quantity = 0; // Items wanted by customer default to 0
						cCheese.milkQuantity = "70%"; // % of milk in item
						cout << "Cream Cheese - " << cCheese.milkQuantity << " Milk - £2" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						cCheese.quantity = userInputItem; // Sets the quantity to user entered amount
						cCheeseTotal = multiply(cCheese.value, cCheese.quantity); // Multiply function to multiply cheese cost by quantity
						cout << "That comes to £" << cCheeseTotal << endl;
					}

					if (userInput == 4) {
						dairy sCheese; // Defines sliced cheese using itemInfo class; creating an sCheese object
						sCheese.value = 1; // Price of item
						sCheese.quantity = 0; // Items wanted by customer default to 0
						sCheese.milkQuantity = "30%"; // % of milk in item
						cout << "Sliced Cheese - " << sCheese.milkQuantity << " Milk - £1" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						sCheese.quantity = userInputItem; // Sets the quantity to user entered amount
						sCheeseTotal = multiply(sCheese.value, sCheese.quantity); // Multiply function to multiply cheese cost by quantity
						cout << "That comes to £" << sCheeseTotal << endl;
					}

					userInputMain = 0; // Sends user back to section selection screen

				}
				while (userInputMain == 2) { // Go to Bakery products

					class bakery : public itemInfo { // Creating derived class bakery from itemInfo
					public:
						string bakeDate;
					};

					cout << "Welcome to the bakery section." << endl << "1. White Bread - £2" << endl << "2. Brown Bread - £4" << endl << "3. Doughnuts - £5" << endl << "4. Cookies - £2" << endl;

					// userInput = 0; // Resetting userInput to 0
					cin >> userInput;

					if (userInput == 1) {
						bakery wBread; // Defines white bread using itemInfo class; creating a wBread object
						wBread.value = 2; // Price of item
						wBread.quantity = 0; // Items wanted by customer default to 0
						wBread.bakeDate = "21/01/24"; // Date item was made in bakery
						cout << "White Bread - Baked on " << wBread.bakeDate << " - £2" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						wBread.quantity = userInputItem; // Sets the quantity to user entered amount
						wBreadTotal = multiply(wBread.value, wBread.quantity); // Multiply function to multiply bread cost by quantity
						cout << "That comes to £" << wBreadTotal << endl;
					}

					if (userInput == 2) {
						bakery bBread; // Defines brown bread using itemInfo class; creating a bBread object
						bBread.value = 4; // Price of item
						bBread.quantity = 0; // Items wanted by customer default to 0
						bBread.bakeDate = "22/01/24"; // Date item was made in bakery
						cout << "Brown Bread - Baked on " << bBread.bakeDate << " - £4" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						bBread.quantity = userInputItem; // Sets the quantity to user entered amount
						bBreadTotal = multiply(bBread.value, bBread.quantity); // Multiply function to multiply bread cost by quantity
						cout << "That comes to £" << bBreadTotal << endl;
					}

					if (userInput == 3) {
						bakery doughnut; // Defines doughnut using itemInfo class; creating a doughnut object
						doughnut.value = 5; // Price of item
						doughnut.quantity = 0; // Items wanted by customer default to 0
						doughnut.bakeDate = "23/01/24"; // Date item was made in bakery
						cout << "Doughnuts - Baked on " << doughnut.bakeDate << " - £5" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						doughnut.quantity = userInputItem; // Sets the quantity to user entered amount
						doughnutTotal = multiply(doughnut.value, doughnut.quantity); // Multiply function to multiply doughnut cost by quantity
						cout << "That comes to £" << doughnutTotal << endl;
					}

					if (userInput == 4) {
						bakery cookie; // Defines cookie using itemInfo class; creating a cookie object
						cookie.value = 2; // Price of item
						cookie.quantity = 0; // Items wanted by customer default to 0
						cookie.bakeDate = "21/01/24"; // Date item was made in bakery
						cout << "Cookies - Baked on " << cookie.bakeDate << " - £2" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						cookie.quantity = userInputItem; // Sets the quantity to user entered amount
						cookieTotal = multiply(cookie.value, cookie.quantity); // Multiply function to multiply cookie cost by quantity
						cout << "That comes to £" << cookieTotal << endl;
					}

					userInputMain = 0; // Sends user back to section selection screen

				}
				if (userInputMain == 3) { // Go to Canned products

					class canned : public itemInfo { // Creating derived class canned from itemInfo
					public:
						string expiresOn;
					};

					cout << "Welcome to the canned section." << endl << "1. Tomato Soup - £2" << endl << "2. Spam - £1" << endl << "3. Canned Tuna - £2" << endl;

					userInput = 0; // Resetting userInput to 0
					cin >> userInput;

					if (userInput == 1) {
						canned tSoup; // Defines tomato soup using itemInfo class; creating a tSoup object
						tSoup.value = 2; // Price of item
						tSoup.quantity = 0; // Items wanted by customer default to 0
						tSoup.expiresOn = "04/08/25"; // Date item will expire
						cout << "Tomato Soup - Expires on " << tSoup.expiresOn << " - £2" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						tSoup.quantity = userInputItem; // Sets the quantity to user entered amount
						tSoupTotal = multiply(tSoup.value, tSoup.quantity); // Multiply function to multiply soup cost by quantity
						cout << "That comes to £" << tSoupTotal << endl;
					}

					if (userInput == 2) {
						canned spam; // Defines spam using itemInfo class; creating a spam object
						spam.value = 1; // Price of item
						spam.quantity = 0; // Items wanted by customer default to 0
						spam.expiresOn = "24/04/27"; // Date item will expire
						cout << "Spam - Expires on " << spam.expiresOn << " - £1" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						spam.quantity = userInputItem; // Sets the quantity to user entered amount
						spamTotal = multiply(spam.value, spam.quantity); // Multiply function to multiply spam cost by quantity
						cout << "That comes to £" << spamTotal << endl;
					}

					if (userInput == 3) {
						canned cTuna; // Defines canned tuna using itemInfo class; creating a cTuna object
						cTuna.value = 2; // Price of item
						cTuna.quantity = 0; // Items wanted by customer default to 0
						cTuna.expiresOn = "25/12/26"; // Date item will expire
						cout << "Canned Tuna - Expires on " << cTuna.expiresOn << " - £1" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						cTuna.quantity = userInputItem; // Sets the quantity to user entered amount
						cTunaTotal = multiply(cTuna.value, cTuna.quantity); // Multiply function to multiply tuna cost by quantity
						cout << "That comes to £" << cTunaTotal << endl;
					}

					userInputMain = 0; // Sends user back to section selection screen

				}
				if (userInputMain == 4) { // Go to Clothing products

					class clothing : public itemInfo { // Creating derived class clothing from itemInfo
					public:
						string percentCotton;
					};

					cout << "Welcome to the clothing section." << endl << "1. T-Shirt - £5" << endl << "2. Trousers - £8" << endl << "3. Coat - £20" << endl << "4. Shoes - £10" << endl;

					userInput = 0; // Resetting userInput to 0
					cin >> userInput;

					if (userInput == 1) {
						clothing tShirt; // Defines tshirt using itemInfo class; creating a tShirt object
						tShirt.value = 5; // Price of item
						tShirt.quantity = 0; // Items wanted by customer default to 0
						tShirt.percentCotton = "90%"; // Percentage of cotton in item
						cout << "T-Shirt - " << tShirt.percentCotton << " Cotton - £5" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						tShirt.quantity = userInputItem; // Sets the quantity to user entered amount
						tShirtTotal = multiply(tShirt.value, tShirt.quantity); // Multiply function to multiply tshirt cost by quantity
						cout << "That comes to £" << tShirtTotal << endl;
					}

					if (userInput == 2) {
						clothing trousers; // Defines trousers using itemInfo class; creating a trousers object
						trousers.value = 8; // Price of item
						trousers.quantity = 0; // Items wanted by customer default to 0
						trousers.percentCotton = "80%"; // Percentage of cotton in item
						cout << "Trousers - " << trousers.percentCotton << " Cotton - £8" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						trousers.quantity = userInputItem; // Sets the quantity to user entered amount
						trousersTotal = multiply(trousers.value, trousers.quantity); // Multiply function to multiply trouser cost by quantity
						cout << "That comes to £" << trousersTotal << endl;
					}

					if (userInput == 3) {
						clothing coat; // Defines coat using itemInfo class; creating a coat object
						coat.value = 20; // Price of item
						coat.quantity = 0; // Items wanted by customer default to 0
						coat.percentCotton = "20%"; // Percentage of cotton in item
						cout << "Coat - " << coat.percentCotton << " Cotton - £20" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						coat.quantity = userInputItem; // Sets the quantity to user entered amount
						coatTotal = multiply(coat.value, coat.quantity); // Multiply function to multiply coat cost by quantity
						cout << "That comes to £" << coatTotal << endl;
					}

					if (userInput == 4) {
						clothing shoes; // Defines shoes using itemInfo class; creating a shoes object
						shoes.value = 10; // Price of item
						shoes.quantity = 0; // Items wanted by customer default to 0
						shoes.percentCotton = "10%"; // Percentage of cotton in item
						cout << "Shoes - " << shoes.percentCotton << " Cotton - £10" << endl << "How many do you want? " << endl;
						userInputItem = 0; // Resets user input
						cin >> userInputItem;
						shoes.quantity = userInputItem; // Sets the quantity to user entered amount
						shoesTotal = multiply(shoes.value, shoes.quantity); // Multiply function to multiply shoes cost by quantity
						cout << "That comes to £" << shoesTotal << endl;
					}

					userInputMain = 0; // Sends user back to section selection screen

				}
				if (userInputMain == 5) { // Go to Checkout

					// checkout

					// Adds up every item to get the overall cost
					int dairyTotal1 = addUp(milkTotal, cheeseTotal);
					int dairyTotal2 = addUp(cCheeseTotal, sCheeseTotal);
					int dairyTotal = addUp(dairyTotal1, dairyTotal2);

					int bakeryTotal1 = addUp(wBreadTotal, bBreadTotal);
					int bakeryTotal2 = addUp(doughnutTotal, cookieTotal);
					int bakeryTotal = addUp(bakeryTotal1, bakeryTotal2);

					int cannnedTotal1 = addUp(tSoupTotal, spamTotal);
					int cannedTotal = addUp(cannnedTotal1, cTunaTotal);

					int clothingTotal1 = addUp(tShirtTotal, trousersTotal);
					int clothingTotal2 = addUp(coatTotal, shoesTotal);
					int clothingTotal = addUp(clothingTotal1, clothingTotal2);

					int totalTotal1 = addUp(dairyTotal, bakeryTotal);
					int totalTotal2 = addUp(cannedTotal, clothingTotal);
					int totalTotal = addUp(totalTotal1, totalTotal2);

					cout << "Your order comes to: £" << totalTotal << endl;

					// banking
					// Getting card details

					string bankNum[userMaxCount]; // Creating card name array

					bankNum[0] = { "1" };
					bankNum[1] = { "1827867181728173" }; // Bank Number array
					bankNum[2] = { "0183674891038927" };

					string sortCode[userMaxCount]; // Creating sort code array

					sortCode[0] = { "1" };
					sortCode[1] = { "12345678" }; // Sorting code array
					sortCode[2] = { "88888888" };

					string secNum[userMaxCount]; // Creating security number array

					secNum[0] = { "1" };
					secNum[1] = { "123" }; // Security number array
					secNum[2] = { "456" };

					string cardName[userMaxCount]; // Creating card name array

					cardName[0] = { "1" };
					cardName[1] = { "John" }; // Card name array
					cardName[2] = { "James" };

					string enteredBankNum; // Variables for user entered values
					string enteredSort;
					string enteredSec;
					string enteredName;

					bool detailsFound = false; // Checking if banking details are correct; default set to false
					while (detailsFound == false) {
						cout << "Enter your bank card number now: " << endl;
						cin >> enteredBankNum; // User enters card number

						cout << "Enter your sort number now: " << endl;
						cin >> enteredSort; // User enters sort number

						cout << "Enter your security number now: " << endl;
						cin >> enteredSec; // User enters security number

						cout << "Enter your card name now: " << endl;
						cin >> enteredName; // User enters card name

						if (bankNum[i] == enteredBankNum && sortCode[i] == enteredSort) { // If both bankNum and sortCode are correct;
							if (secNum[i] == enteredSec && cardName[i] == enteredName) { // Then if secNum and cardName are also correct;
								detailsFound = true; // The details have been confirmed; detailsFound is true
								cout << "Bank details confirmed. Have a nice day!" << endl;
								programDone = true; // The program is done
								exit; // Redundancy 
							}
							else {
								cout << "Invalid details. Please try again."; // User is not found; loops
							}
						}
						else {
							cout << "Invalid details. Please try again." << endl; // User is not found; loops
						}
					}
				}

				if (userInputMain == 6) { // Exiting program
					exit;
				}

				else {
					"Invalid input, please try again."; // Invalid value entered, loop
					userInputMain = 0;
				}
			}
		}
	}
	return 0;
}