// main for books version of contract program
// file:   ch6cntr2.cpp

#include <iostream.h>
#include "contract.h"

char GetProperty();
char GetOperatorChoice();
int GetContractNum();

void DisplayInfo(Contract contract);
void ChangeInfo(Contract& contract);

void DisplayClosingMessage();
void DisplayIntro();

int GetSquareFootage();
int GetNumDesks();
int GetNumDays();

void ProcessUserChoices();

void main()
{
	DisplayIntro();
	ProcessUserChoices();
	DisplayClosingMessage();
}




char GetOperatorChoice()
{// please enter choice
// make a while loop and talk about redundancy.
	char choice;

	cout << "Please choose one of the following operations\n";
	cout << "         'D' to display the information for a contract\n";
	cout << "         'C' to change the information for a contract\n";
	cout << "         'Q' to quit the program\n";
	cin >> choice;
	return choice;
}

int GetContractNum()
{// loop choice 1-5

	int num;
	cout << "\nPlease choose which contract (1 through 5) that you wish to work with\n";
	cout << "Choose 0 (zero) when you are finished with this operation.\n";
	cin >> num;
	return num;

}


void 	ChangeInfo(Contract& contract)
{
	char property;

	property = GetProperty();
	while ((property != 'N') && (property != 'n'))
	{	switch (property)
		{	case 'S':
			case 's':
				int sqFootage;
				sqFootage = GetSquareFootage();
				contract.ChangeSquareFootage(sqFootage);
				break;
			case 'K':
			case 'k':
				int numDesks;
				numDesks = GetNumDesks();
				contract.ChangeNumDesks(numDesks);
				break;
			case 'Y':
			case 'y':
				int numDays;
				numDays = GetNumDays();
				contract.ChangeNumDays(numDays);
				break;
			default:
				cout << "\nInvalid choice of properties. Please try again\n";

		}  // end switch
		property = GetProperty();
	}
}

void DisplayInfo(Contract contract)
{
	int sqFootage;
	sqFootage = contract.ProvideSquareFootage();
	cout << "\n\nThe square footage for the contract is: " << sqFootage << endl;

	int numDesks;
	numDesks = contract.ProvideNumberOfDesks();
	cout << "The number of desks for the contract is: " << numDesks << endl;

	int numDays;
	numDays = contract.ProvideNumberOfDays();
	cout << "The number of days for the contract is: " << numDays << endl;

	double charge;
	charge = contract.ProvidePerWeekCharge();
	cout << "The per week charge for the contract is: " << charge << endl;
	cout << endl << endl << endl;

}

char GetProperty()
{  char property;
	cout << "Please enter the letter corresponding to the property you want to change\n";
	cout << "          'S':  square Footage\n";
	cout << "          'K':  number of desks\n";
	cout << "          'Y':  number of days per week\n";
	cout << "          'N':  none\n";
	cin >> property;
	return property;
}

void 	DisplayClosingMessage()
{	cout << "\n\n\n     H A V E   F U N";
}

void DisplayIntro()
{	cout << "               W E L CO M E   TO   O L Y M P I A ' S\n";
	cout << "         O F F I C E   C O N T R A C T   P R O G R A M\n\n\n";
}

int GetSquareFootage()
{	int sqFootage;
	cout << "\nWhat is the new square footage for the contract?";
	cin >> sqFootage;
	return sqFootage;
}


int GetNumDesks()
{	int numDesks;
	cout << "\nWhat is the new number of desks for the contract?";
	cin >> numDesks;
	return numDesks;
}


int GetNumDays()
{	int numDays;
	cout << "\nWhat is the new number of days for the contract?";
	cin >> numDays;
	return numDays;
}

void ProcessUserChoices()
{	// Code to create the five instances
	Contract contract1(1000, 3, 5);
	Contract contract2(500, 10, 3);
	Contract contract3(200, 1, 4);
	Contract contract4(2000, 20, 5);
	Contract contract5(300, 2, 2);



bool done = false;

char choice;
int contractNum;

while (!done)
	{  choice = GetOperatorChoice();
		switch (choice)
		{	case 'D':
			case 'd':
				contractNum = GetContractNum();
				while (contractNum != 0)
				{	switch (contractNum)
					{	case 1:
							DisplayInfo(contract1);
							break;
						case 2:
							DisplayInfo(contract2);
							break;
						case 3:
							 DisplayInfo(contract3);
							break;
						case 4:
							 DisplayInfo(contract4);
							break;
						case 5:
							 DisplayInfo(contract5);
							break;


						default:
							cout << "Invalid contract. Please try again\n";
					}
					contractNum = GetContractNum();
				}

				break;  // the break statement for case 'd'

			case 'C':
			case 'c':
				contractNum =  GetContractNum();
				while (contractNum != 0)
				{
					switch (contractNum)
					{	case 1:
							ChangeInfo(contract1);
							break;
						case 2:
						ChangeInfo(contract2);
								break;
						case 3:
							ChangeInfo(contract3);
							break;
						case 4:
							ChangeInfo(contract4);
							break;
						case 5:
							ChangeInfo(contract5);
							break;
						default:
							cout << "Invalid contract number. \n";
					}
					contractNum = GetContractNum();
				 }

				break;
			case 'Q':
			case 'q':
				cout << "Do you want to really want top quit (Y) or (N)\n";
				char answ;
				cin >> answ;
				if ((answ =='Y') || (answ == 'y'))
				{
					done = true;
				}

				break;
			default:
				cout << "Invalid choice. Please try again\n";

		}  // end switch

	}
}