#include "DeliverySystem.h"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

const int foodMenuSize = 21;
const int breakfastMenuSize = 8;
const int lunchMenuSize = 8;
const int dinnerMenuSize = 9;

void Menu::showOption()
{
	cout << "\n";
	cout<<"\t      #################################################   "<<endl;
	cout<<"\t      ##    WELCOME TO FOOD DELIVERY SYSTEM MENU     ###   "<<endl;
	cout<<"\t      ##   =====================================     ##|# "<<endl;
	cout<<"\t      ##                                             ##|||#"<<endl;
	cout<<"\t      ##                                             ##|||#"<<endl;
	cout<<"\t      ##    1) VIEW MENU & MAKE ORDER                ##|||#"<<endl;
	cout<<"\t      ##                                             ##|||#"<<endl;
	cout<<"\t      ##    2) DISPLAY ORDER                         ##|||#"<<endl;
	cout<<"\t      ##                                             ##|||#"<<endl;	
	cout<<"\t      ##    3) MAKE PAYMENT                          ##|||#"<<endl;
	cout<<"\t      ##                                             ##|||#"<<endl;
	cout<<"\t      ##    4) EXIT                                  ##|||#"<<endl;			
	cout<<"\t      ##                                             ##|||#"<<endl;
	cout<<"\t      ##                                             ##|||#"<<endl;
	cout<<"\t      ##                                             ##|||#"<<endl;
	cout<<"\t      ##   =====================================     ##|||#"<<endl;
	cout<<"\t      #################################################|||#"<<endl;
	cout<<"\t       #-----------------------------------------------\\||#"<<endl;
	cout<<"\t        #-----------------------------------------------\\|#"<<endl;
	cout<<"\t         ##################################################"<<endl;		
	cout<<"\n\n";
}

Menu::Menu(string n, double p)
{
	setName(n);
	setPrice(p);
}

void Menu::setName(string n)
{
	name = n;
}

void Menu::setPrice(double p)
{
	price = p;
}

string Menu::getName()
{
	return name;
}

double Menu::getPrice()
{
	return price;
} 

Breakfast::Breakfast()
{
	setName("");
	setPrice(0.0);
}

Breakfast::Breakfast(Menu *m, int i)
{
	setName(m[i].getName());
	setPrice(m[i].getPrice());
}

Lunch::Lunch()
{
	setName("");
	setPrice(0.0);
}

Lunch::Lunch(Menu *m, int i)
{
	setName(m[i].getName());
	setPrice(m[i].getPrice());
}

Dinner::Dinner()
{
	setName("");
	setPrice(0.0);
}

Dinner::Dinner(Menu *m, int i)
{
	setName(m[i].getName());
	setPrice(m[i].getPrice());
}

Order::Order()
{
	setName("");
	setPrice(0.0);
	quantity = 0;
	payment = new Payment;
}

Order::Order(Menu* m, int i, int q)
{
	setName(m[i-1].getName());
	setPrice(m[i-1].getPrice());
	setQuantity(q);
}

Order::Order(Breakfast* b, int i, int q)
{
	setName(b[i-1].getName());
	setPrice(b[i-1].getPrice());
	setQuantity(q);
}

Order::Order(Lunch* l, int i, int q)
{
	setName(l[i-1].getName());
	setPrice(l[i-1].getPrice());
	setQuantity(q);
}

Order::Order(Dinner* d, int i, int q)
{
	setQuantity(q);
	setName(d[i-1].getName());
	setPrice(d[i-1].getPrice());
}

double Order::getSubtotal()
{
	double subtotal;
	subtotal = this->getPrice() * this->getQuantity();
	return subtotal;
}

void Order::setQuantity(int i)
{
	int a = i;
	while(a<1){
		cout<<"\t!!!!! Invalid input. Please enter again. !!!!!\n";
		cout<<"\tEnter the quantity again: ";
		cin>>a;
	};
	quantity = i;
}

void Order::addAmount(float a)
{
	payment->setAmount(a);
}

void OnlineBanking::authorise()
{	
	cout << "\n\t\t\t PLEASE ENTER YOUR BANK NAME: ";
	cin >> bank;
	cout << "\t\t\t PLEASE ENTER YOUR USERNAME: ";
	cin >> username;
	cout << "\t\t\t PLEASE ENTER YOUR PASSWORD: ";
	cin >> password;
	
	cout << "\n\t\t\t PROCESSING..." << endl << endl;
	system("pause");
	cout << "\n\t\t\t PAYMENT SUCCESS" << endl << endl;
}

void Card::authorise()
{
	cout << "\n\t\t\t PLEASE ENTER YOUR CARD NUMBER: ";
	cin >> cardNo;
	cout << "\t\t\t PLEASE ENTER YOUR CARD CVV: ";
	cin >> cvv;
	
	cout << "\n\t\t\t PROCESSING..." << endl << endl;
	system("pause");
	cout << "\n\t\t\t PAYMENT SUCCESS" << endl << endl;
}

void Cash::getChange(float a)
{
	amount = a;
	do
	{
	cout << "\n\t\t\t PLEASE ENTER THE AMOUNT YOU WANT TO PAID: RM ";
	cin >> paid;

	change = paid-amount;
	
	if(paid>=amount)
	cout << "\t\t\t PLEASE REMEMBER TO TAKE YOUR CHANGE: RM " << change << endl; 
	else
	cout << "\t\t\t PAYMENT NOT ENOUGH" << endl; 
	
	}while(paid<amount);
}

Shop::Shop(string n, string a)
{
	name = n;
	address = a;
}

void Shop::showMenu()
{
	menu->showOption();
}

void Shop::setFoodMenu()
{
	menu = new Menu[foodMenuSize];
	Menu temp[] = { Menu("Roti Sardin", 3.50),
					Menu("Roti Canai", 1.50),
					Menu("Roti Telur", 2.30),
					Menu("Roti Boom", 3.50),
					Menu("Nasi Lemak Telur", 4.00),
					Menu("Kopi O", 2.00),
					Menu("Teh Tarik", 2.20),
					Menu("Milo Kosong", 2.00),
					Menu("Teh O Limao Ais", 2.30),
					Menu("Sirap Limao Ais", 2.20),
					Menu("Nasi Goreng Kampung", 6.00),
					Menu("Nasi Goreng Pattaya", 6.50),
					Menu("Mee Goreng", 5.00),
					Menu("Maggi Goreng", 5.00),
					Menu("Nasi Ayam Merah", 7.00),
					Menu("Nasi Goreng Tomyam", 6.50),
					Menu("Extra Fried Egg x1", 1.00),
					Menu("Extra Fried Chicken x1", 3.00),
					Menu("BBQ Chicken (1/4 of the chicken)", 9.90),
					Menu("BBQ Chicken (1/2 of the chicken)", 17.50),
					Menu("White Rice (1 portion)", 1.00)	};
	for(int i=0; i<foodMenuSize; i++)
		menu[i] = temp[i];
}

void Shop::setBreakfastMenu()
{
	breakfastMenu = new Breakfast[breakfastMenuSize];
	Breakfast temp[] = {	Breakfast(menu,0),
							Breakfast(menu,1),
							Breakfast(menu,2),
							Breakfast(menu,3),
							Breakfast(menu,4),
							Breakfast(menu,5),
							Breakfast(menu,6),
							Breakfast(menu,7)	};
	for(int i=0; i<breakfastMenuSize; i++)
		breakfastMenu[i] = temp[i];
}

void Shop::setLunchMenu()
{
	lunchMenu = new Lunch[lunchMenuSize];
	Lunch temp[] = {	Lunch(menu,8),
						Lunch(menu,9),
						Lunch(menu,10),
						Lunch(menu,11),
						Lunch(menu,12),
						Lunch(menu,13),
						Lunch(menu,15),
						Lunch(menu,16)	};
	for(int i=0; i<lunchMenuSize; i++)
		lunchMenu[i] = temp[i];
}

void Shop::setDinnerMenu()
{
	dinnerMenu = new Dinner[dinnerMenuSize];
	Dinner temp[] = {	Dinner(menu,6),
						Dinner(menu,8),
						Dinner(menu,9),
						Dinner(menu,14),
						Dinner(menu,16),
						Dinner(menu,17),
						Dinner(menu,18),
						Dinner(menu,19),
						Dinner(menu,20)	};
	for(int i=0; i<dinnerMenuSize; i++)
		dinnerMenu[i] = temp[i];
}

void Shop::displayAllMenu()
{
	cout<<"\n\t\t\t\tWelcome to "<<name;
	cout<<"\n\n\t\t\t\t     All Menu\n\n";
	cout<<"\tNo.\tFood Name\t\t\t\tPrice(RM)\n";
	cout<<"\t---------------------------------------------------------\n";
	for(int i=0; i<foodMenuSize; i++){
		cout<<"\t"<<(i+1)<<"\t"<<left<<setw(42)<<menu[i].getName()<<fixed<<setprecision(2)<<menu[i].getPrice()<<"\n\n";
	}	
}

void Shop::displayBreakfastMenu()
{
	cout<<"\n\t\t\t\tWelcome to "<<name;
	cout<<"\n\n\t\t\t\t    Breakfast Menu\n\n";
	cout<<"\tNo.\tFood Name\t\t\t\tPrice(RM)\n";
	cout<<"\t---------------------------------------------------------\n";
	for(int i=0; i<breakfastMenuSize; i++){
		cout<<"\t"<<(i+1)<<"\t"<<left<<setw(42)<<breakfastMenu[i].getName()<<fixed<<setprecision(2)<<breakfastMenu[i].getPrice()<<"\n\n";
	}	
}

void Shop::displayLunchMenu()
{
	cout<<"\n\t\t\t\tWelcome to "<<name;
	cout<<"\n\n\t\t\t\t    Lunch Menu\n\n";
	cout<<"\tNo.\tFood Name\t\t\t\tPrice(RM)\n";
	cout<<"\t---------------------------------------------------------\n";
	for(int i=0; i<lunchMenuSize; i++){
		cout<<"\t"<<(i+1)<<"\t"<<left<<setw(42)<<lunchMenu[i].getName()<<fixed<<setprecision(2)<<lunchMenu[i].getPrice()<<"\n\n";
	}	
}

void Shop::displayDinnerMenu()
{
	cout<<"\n\t\t\t\tWelcome to "<<name;
	cout<<"\n\n\t\t\t\t    Dinner Menu\n\n";
	cout<<"\tNo.\tFood Name\t\t\t\tPrice(RM)\n";
	cout<<"\t---------------------------------------------------------\n";
	for(int i=0; i<dinnerMenuSize; i++){
		cout<<"\t"<<(i+1)<<"\t"<<left<<setw(42)<<dinnerMenu[i].getName()<<fixed<<setprecision(2)<<dinnerMenu[i].getPrice()<<"\n\n";
	}	
}

void Shop::setShopName(string n)
{
	name = n;
}

void Shop::setAddress(string a)
{
	address = a;
}

string Shop::getName()
{
	return name;
}

string Shop::getAddress()
{
	return address;
}

Account::Account()
{
	username = "";
	password = "";
};

void Account::registration(string u, string p)
{
	username = u;
	password = p;
	
  	cout << "\n\t\t\t Registration success !" << endl;
}

bool Account::login()
{
	string id, pw;
	
	cout<<"\n\t\t\t      LOGIN FORM" << endl;
  	cout<<"\t\t\t----------------------------" << endl;	
	
	cout << "\t\t\t Enter your login ID: ";
	cin >> id;
	
	cout << "\t\t\t Enter your password: ";
	cin >> pw;
	
	if((id==username)&&(pw==password))
	return true;
	else
	return false;
}

User::User()
{
	account = new Account;
	fullName = "";
	phone = "";
}

void User::setInfo(string n, string p)
{
	fullName = n;
	phone = p;
}

void User::getInfo()
{
	cout<<"\n\t\t\t     GENERAL USER INFORMATION" << endl;
  	cout<<"\t\t\t----------------------------" << endl;
  	cout<<"\t\t\tNAME: " << fullName << endl;
  	cout<<"\t\t\tPHONE: " << phone << endl;
}

void User::mainPage()
{
	cout<<"\n";
	cout<<"\t               ###############################          "<<endl;
	cout<<"\t            #####################################       "<<endl;
	cout<<"\t         ###########################################    "<<endl;
	cout<<"\t      ################################################# "<<endl;
	cout<<"\t        ##     WELCOME TO FOOD DELIVERY SYSTEM     ##   "<<endl;
	cout<<"\t        ##   ===================================   ##   "<<endl;
	cout<<"\t        ##      ________                           ##   "<<endl;
	cout<<"\t        ##     | Order: |                ____      ##   "<<endl;
	cout<<"\t        ##     |  FOOD  |  --->        _|    |_ /  ##   "<<endl;
	cout<<"\t        ##     |        |        .....|__FOOD _|   ##   "<<endl;
	cout<<"\t        ##     |  Yes   |               @     @ \\  ##   "<<endl;	
	cout<<"\t        ##     |__No____|                          ##   "<<endl;
	cout<<"\t        ##     |___()___|                          ##   "<<endl;
	cout<<"\t        ##                                         ##   "<<endl;			
	cout<<"\t        ##         1) REGISTER                     ##   "<<endl;
	cout<<"\t        ##         2) LOGIN                        ##   "<<endl;
	cout<<"\t        ##         3) EXIT                         ##   "<<endl;
	cout<<"\t        ##   ===================================   ##   "<<endl;
	cout<<"\t        #############################################   "<<endl;
	cout<<"\t      ################################################# "<<endl;
	cout<<"\n\n";
}

void User::registration()
{
	string id, password;
	
	cout<<"\n\t\t\t     REGISTERATION FORM" << endl;
  	cout<<"\t\t\t----------------------------" << endl;
  
  	cin.ignore();
	cout << "\t\t\t Name: ";
  	getline(cin, fullName);
  
	cout << "\t\t\t Mobile No: ";
  	cin >> phone;
  
	cout << "\t\t\t Login: ";
  	cin >> id;
  	
	cout << "\t\t\t Password: ";
  	cin >> password;
  	
  	account->registration(id, password);
}

bool User::verify()
{
	return account->login();
}

Seller::Seller(Shop *s, string v)
{
	shop = s;
	vehicleNo = v;
}

void Seller::getInfo()
{
	cout<<"\t\t\t|       SELLER INFORMATION      |" << endl;
  	cout << "\t\t\t---------------------------------" << endl;
  	cout<<"\t\t\t|NAME: " << fullName << "                     |" << endl;
  	cout<<"\t\t\t|PHONE: " << phone << "             |" << endl;
  	cout<<"\t\t\t|VEHICLE NUMBER: " << vehicleNo << "         |" << endl;
  	cout<<"\t\t\t|SHOP NAME: " << shop->getName() << "     |" <<  endl;
  	cout<<"\t\t\t|SHOP ADDRESS: " << shop->getAddress() << "      |" << endl;
}

Customer::Customer()
{
	address = "";
	numOrder = 0;
	orderList = new Order[foodMenuSize];
}

void Customer::addOrder(Order *o)
{
	bool exist = false;
	for(int i=0; i<numOrder; i++){
		string str1, str2;
		str1 = orderList[i].getName();
		str2 = o->getName();
		if(str1==str2){
			exist = true;
			int newQty = o->getQuantity() + orderList[i].getQuantity();
			orderList[i].setQuantity(newQty);
			break;
		}
	}
	if(!exist){
		orderList[numOrder] = *o;
		numOrder++;
	}
	cout<<"\tYour order has been added.\n\n";
}

float Customer::displayOrder()
{
	float total;
	cout<<"\n\t\t\t\tHere is your orders: \n\n\n";
	cout<<"\tNo.\tFood Name\t\t\t\tPrice(RM)\tQuantity\tSubtotal\n";
	cout<<"\t----------------------------------------------------------------------------------------\n";
	for(int i=0; i<numOrder; i++){
		cout<<"\t"<<(i+1)<<"\t"<<left<<setw(42)<<orderList[i].getName()<<fixed<<setprecision(2)<<orderList[i].getPrice();
		cout<<"\t\t   "<<orderList[i].getQuantity()<<"\t\t  "<<orderList[i].getSubtotal()<<endl;
		total += orderList[i].getSubtotal();
	}
	cout<<"\n\tThe total price for your current orders is RM "<<this->getTotal()<<endl;
	
	return total;
}

double Customer::getTotal()
{
	double total = 0;
	for(int i=0; i<numOrder; i++)
		total += orderList[i].getSubtotal();
	return total;
}

void Customer::setInfo(string a)
{
	address = a;
}

void Customer::getInfo()
{
	cout<<"\n\t\t\t     CUSTOMER INFORMATION" << endl;
  	cout<<"\t\t\t----------------------------" << endl;
  	cout<<"\t\t\tNAME: " << fullName << endl;
  	cout<<"\t\t\tPHONE: " << phone << endl;
  	cout<<"\t\t\tADDRESS: " << address << endl;
}


