// User Includes

#include "person.h"

person::person()
{
	blankPerson();
}

bool person::operator ==(const person& EQ)
{

	return( !( 	strcmp(firstName, EQ.firstName) ||
		strcmp(lastName, EQ.lastName) ||
		strcmp(address, EQ.address)||
		strcmp(city, EQ.city) ||
		strcmp(province, EQ.province) ||
		strcmp(postalCode, EQ.postalCode) ||
		strcmp(country, EQ.country) ||
		strcmp(phoneHome, EQ.phoneHome) ||
		strcmp(phoneCell, EQ.phoneCell) ||
		strcmp(email, EQ.email) ) );

}

bool person::operator <(const person& LT)
{
	bool comp = true;
	int ans;

	ans = strcmp(lastName, LT.lastName); 

	if ( ans > 0 )
		return (false);
	
	else if ( ans == 0 )
	{
		ans = strcmp(firstName, LT.firstName); 
		if ( ans > 0 )
			return (false);
		
		else if ( ans == 0 )
		{
			ans = strcmp(address, LT.address); 
			if ( ans > 0 )
				return (false);
			
			else if ( ans == 0 )
			{
				ans = strcmp(city, LT.city); 
				if ( ans > 0 )
					return (false);
				
				else if ( ans == 0 )
				{
					ans = strcmp(province, LT.province); 
					if ( ans > 0 )
						return (false);
					
					else if ( ans == 0 )
					{
						ans = strcmp(postalCode, LT.postalCode); 
						if ( ans > 0 )
							return (false);
						
						else if ( ans == 0 )
						{
							ans = strcmp(country, LT.country); 
							if ( ans > 0 )
								return (false);
							
							else if ( ans == 0 )
							{
								ans = strcmp(phoneHome, LT.phoneHome); 
								if ( ans > 0 )
									return (false);
								
								else if ( ans == 0 )
								{
									ans = strcmp(phoneCell, LT.phoneCell); 
									if ( ans > 0 )
										return (false);
									
									else if ( ans == 0 )
									{
										ans = strcmp(email, LT.email); 
										if ( ans > 0 )
											return (false);
										
										else if ( ans == 0 )
											return (false);
									} // phoneCell
								} // phoneHome
							} // country
						} // postalCode
					} // province
				} // city
			} // address
		} // firstName
	} // lastName

	return (comp);

}

bool person::operator >(const person& GT)
{
	if ( !(*this < GT) && !(*this == GT) )
		return (true);

	else 
		return (false);

}

bool person::operator >=(const person& GTE)
{
	if ( !(*this < GTE) )
		return (true);

	else 
		return (false);

}

bool person::operator <=(const person& LTE)
{
	if ( !(*this > LTE) )
		return (true);

	else 
		return (false);

}

bool person::operator !=(const person& NE)
{
	if ( !(*this == NE) )
		return (true);

	else 
		return (false);

}

void person::blankPerson()
{
	memset(firstName, 0, NAME_SIZE);
	memset(lastName, 0, NAME_SIZE);
	memset(address, 0, NAME_SIZE);
	memset(city, 0, NAME_SIZE);
	memset(province, 0, PROVINCE_SIZE);
	memset(postalCode, 0, PROVINCE_SIZE);
	memset(country, 0, COUNTRY_SIZE);
	memset(phoneHome, 0, PHONE_SIZE);
	memset(phoneCell, 0, PHONE_SIZE);
	memset(email, 0, NAME_SIZE);
}

void person::displayPerson()
{
	cout << endl
		<< "First Name: " << firstName << endl
		<< "Last Name: " << lastName << endl
		<< "Address: " << address << endl
		<< "City: " << city << endl
		<< "Province: " << province << endl
		<< "Postal Code: " << postalCode << endl
		<< "Country: " << country << endl
		<< "Phone (Home): " << phoneHome << endl
		<< "Phone (Cell): " << phoneCell << endl
		<< "E-Mail: " << email << endl
		<< endl;

}

void person::inputPerson()
{

	cout << endl << "First Name: ";
	cin.getline(firstName, NAME_SIZE);

	cout << "Last Name: ";
	cin.getline(lastName, NAME_SIZE);
	
	cout << "Address: ";
	cin.getline(address, NAME_SIZE);
	
	cout << "City: ";
	cin.getline(city, NAME_SIZE);
	
	cout << "Province: ";
	cin.getline(province, PROVINCE_SIZE);
	
	cout << "Postal Code: ";
	cin.getline(postalCode, PROVINCE_SIZE);

	cout << "Country: ";
	cin.getline(country, COUNTRY_SIZE);

	cout << "Phone (Home): ";
	cin.getline(phoneHome, PHONE_SIZE);

	cout << "Phone (Cell): ";
	cin.getline(phoneCell, PHONE_SIZE);

	cout << "E-Mail: ";
	cin.getline(email, NAME_SIZE);

}

void person::inputPerson(ifstream &in)
{

	in.getline(firstName, NAME_SIZE);
	in.getline(lastName, NAME_SIZE);
	in.getline(address, NAME_SIZE);
	in.getline(city, NAME_SIZE);
	in.getline(province, PROVINCE_SIZE);
	in.getline(postalCode, PROVINCE_SIZE);
	in.getline(country, COUNTRY_SIZE);
	in.getline(phoneHome, PHONE_SIZE);
	in.getline(phoneCell, PHONE_SIZE);
	in.getline(email, NAME_SIZE);


}

void person::writePerson(ofstream &out)
{
	out << firstName << endl
		<< lastName << endl
		<< address << endl
		<< city << endl
		<< province << endl
		<< postalCode << endl
		<< country << endl
		<< phoneHome << endl
		<< phoneCell << endl
		<< email << endl;
}

int person::checkField(char* buffer, personField field)
{
	int ans;

	switch ( field )
	{
		case FIRST:

			ans = strcmp(buffer, firstName);
			break;

		case LAST:

			ans = strcmp(buffer, lastName);
			break;

		case ADDRESS:

			ans = strcmp(buffer, address);
			break;

		case CITY:

			ans = strcmp(buffer, city);
			break;

		case PROVINCE:

			ans = strcmp(buffer, province);
			break;

		case POSTAL:

			ans = strcmp(buffer, postalCode);
			break;

		case COUNTRY:

			ans = strcmp(buffer, country);
			break;

		case PHONE_HOME:

			ans = strcmp(buffer, phoneHome);
			break;

		case PHONE_CELL:

			ans = strcmp(buffer, phoneCell);
			break;

		case EMAIL:

			ans = strcmp(buffer, email);
			break;

	}

	return(ans);

}