
//File Main.cpp - contains main funtion and testing code

#include <iostream>
using namespace std;

#include <string>
#include "Name.h"
#include "PhoneNumber.h"
#include "Set.h"
#include "Dictionary.h"
#include "SetIterator.h"
 

void main() {
	cout << "Creating the phonebook" << endl;
	Dictionary<string, string, PhoneNumber> phonebook;
	
	//cout << "\nCreating Lou Nel" << endl;
	Name louNel("Lou", "Nel");
	cout << "Creating " << louNel << endl;
	Name sueSmith("Sue", "Smith");
	cout << "Creating " << sueSmith << endl;
	Name johnSmith("John", "Smith");
	cout << "Creating " << johnSmith << endl;
	Name andyJohns("Andy", "Johns");
	cout << "Creating " << andyJohns << endl;
	Name joJames("Jo", "James");
	cout << "Creating " << joJames << endl;
	Name anneJones("Anne", "Jones");
	cout << "Creating " << anneJones << endl;
	Name tomJones("Tom", "Jones");
	cout << "Creating " << tomJones << endl;
	Name roySmith("Roy", "Smith");
	cout << "Creating " << roySmith << endl;
	Name williamSmith("William", "Smith");
	cout << "Creating " << williamSmith << endl;
	Name anneJames("Anne", "James");
	cout << "Creating " << anneJames << endl;
	Name bobSmith("Bob", "Smith");
	cout << "Creating " << bobSmith << endl;
	cout << "Adding " << louNel << endl;
	phonebook.add(louNel.getLastName(), louNel.getFirstName(), *(new PhoneNumber(613, 231, 1277)));
	cout << "Adding " << sueSmith << endl;
	phonebook.add(sueSmith.getLastName(), sueSmith.getFirstName(), *(new PhoneNumber(819, 788, 1237)));
	cout << "Adding " << johnSmith << endl;
	phonebook.add(johnSmith.getLastName(), johnSmith.getFirstName(), *(new PhoneNumber(819, 788, 1237)));
	cout << "Adding " << andyJohns << endl;
	phonebook.add(andyJohns.getLastName(), andyJohns.getFirstName(), *(new PhoneNumber(613, 234, 2222)));
	cout << "Adding " << joJames << endl;
	phonebook.add(joJames.getLastName(), joJames.getFirstName(), *(new PhoneNumber(613, 233,1237)));
	cout << "Adding " << anneJones << endl;
	phonebook.add(anneJones.getLastName(), anneJones.getFirstName(), *(new PhoneNumber(613, 233, 3344)));
	cout << "Adding " << tomJones << endl;
	phonebook.add(tomJones.getLastName(), tomJones.getFirstName(), *(new PhoneNumber(613, 841, 7468)));
	cout << "Adding " << roySmith << endl;
	phonebook.add(roySmith.getLastName(), roySmith.getFirstName(), *(new PhoneNumber(613, 720, 2746)));
	cout << "Adding " << williamSmith << endl;
	phonebook.add(williamSmith.getLastName(), williamSmith.getFirstName(), *(new PhoneNumber(613, 819, 5662)));
	cout << "Adding " << anneJames << endl;
	phonebook.add(anneJames.getLastName(), anneJames.getFirstName(), *(new PhoneNumber(613, 725, 8895)));
	cout << "Adding " << bobSmith << endl;
	phonebook.add(bobSmith.getLastName(), bobSmith.getFirstName(), *(new PhoneNumber(613, 233, 2345)));

	cout << "\nPrinting Phonebook: " << endl;
	cout << phonebook;

	cout << "\nCreating second Sue Smith" << endl;
	Name & aName = Name("Sue", "Smith");
	//cout << "Sue Smith created" << endl;

	//test the includes
	cout << "Checking includesKey function" << endl;
	cout << "\tDoes phonebook include new " << aName << "? ";
	if(phonebook.includesKey(aName.getLastName(), aName.getFirstName()) == true)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	
	cout << "Checking includesValue function" << endl;
	cout << "\tDoes phonebook include number of " << aName << "? ";
	if(phonebook.includesValue(*(phonebook.lookup(aName.getLastName(), aName.getFirstName()))))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	//look up values based on keys
	cout << "\nChecking lookup function for " << aName.getLastName() << ", " << aName.getFirstName() << endl;
	PhoneNumber * number = phonebook.lookup(aName.getLastName(), aName.getFirstName());
	if(number == NULL)
		cout << "\tLookup function FAILED!" << endl;
	//should print "The number of Sue Smith is (819) 788-1237
	cout << "\tThe phone number of " << aName << " is " << *number << endl;;

	cout << "\nChecking == operator of PhoneNumber class" << endl;
	PhoneNumber aNumber("819", "788", "1237");
	cout << "\tDoes " << aName << "'s number equal " << aNumber << "? ";
	if(aNumber == *number)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	cout << "\nCreating Ringo Star" << endl;
	Name  & anotherName = Name("Ringo", "Star");
	PhoneNumber * anotherPhoneNumber = phonebook.lookup(anotherName.getLastName(), anotherName.getFirstName() );
	//should print "The number of Ringo Starr is NULL
	cout << "\tThe number of " << anotherName << " is " << anotherPhoneNumber << endl;;
	//close enough - a bunch of zeros might as well be NULL

	//Test Sets and iterators
	Set<string> categories(phonebook.categories());

	//This loop should print the names and phonenumbers in the phone book
	cout << "\nPrinting Name and Numbers in the phone book using categories and keys functions: " << endl;
	for(SetIterator<string> lastNameIter = categories.begin(); lastNameIter != categories.end(); ++lastNameIter){
		Set<string> keys = phonebook.keys(*lastNameIter);
		for(SetIterator<string> firstNameIter = keys.begin(); firstNameIter != keys.end(); ++firstNameIter){
			cout << *lastNameIter << " " << *firstNameIter << " " << *(phonebook.lookup(*lastNameIter, *firstNameIter)) << endl;
		}
	}

	cout << "\nValues in the phone book: " << endl;
	Set<PhoneNumber> numbers(phonebook.values());
	cout << numbers;
	cout << endl << endl;
}