package com.gmscheduler.model;

/**
 * A <code>Person</code> object represents the owner of schedule.
 * 
 * @author Peter Deschere
 * @author Rebecca Beale
 * @author Jason Fillo
 * @version 1.3
 *
 */
public class Person {
    //class constructor
	public Person(String name) {
		this.name = new String(name);
		this.email= new String();
		this.password = new String();
		//this.id = new Long(0);
		//System.out.println(this.toString());
	}
	
    //class constructor
	public Person(String name, String pw) {
		this.name = new String(name);
		this.email= new String();
		this.password = new String(pw);
		//this.id = new Long(0);
		//System.out.println(this.toString());
	}
	//copy constructor
	public Person(Person u) {
		this.name = new String(u.getName()); 
		this.email = new String(u.getEmail());
		this.password = new String (u.getPassword());
		if (!(u.getId() == null)) {
			this.id = new Long(u.getId());}
	}
	
	//default constructor
	public Person() {
		this.name = new String();
		this.email = new String();
		this.password = new String();
		//this.id = new Long(0);
	}

	/**
	 * Returns the id.
	 * 
	 * @return the id of the <code>Person</code>
	 */
	public Long getId() {
		return id;
	}
	
	/**
	 * Sets the Id. Required for hibernate.
	 * 
	 * @param id the id of the <code>Person</code> in the database
	 */
	private void setId(Long id) {
		this.id = id;
	}
	
	/**
	 * Returns the password.
	 * 
	 * @return the password of the <code>Person</code>
	 */
	public String getPassword() {
		return password;
	}
	
	/**
	 * Sets the password.
	 * 
	 * @param pw the new pw
	 */
	public void setPassword(String pw) {
		this.password = pw;
	}
	
	/**
	 * Returns the name.
	 * 
	 * @return the name of the <code>Person</code>
	 */
	public String getName() {
		if (name==null) {return "";} else {return name;}
	}

	/**
	 * Sets the name.
	 * 
	 * @param name the new name
	 */
	public void setName(String name) {
		this.name = new String(name); 
	}
	
	public String toString() {
		if (name == null) {
			return "";
		} else {
			return name + " | " + email + " | " + id;
		}
	}
	
	
	/**
	 * Returns the email.
	 * 
	 * @return the email of the <code>Person</code>
	 */
	public String getEmail() {
		return email;
	}
	
	/**
	 * Sets the email.
	 * 
	 * @param newemail the new email address
	 */
	public void setEmail(String newemail) {
		this.email = new String(newemail);
	}
	
	/**
	 * Returns true if the password is valid.
	 * 
	 * @param pw the passwrod to compare to
	 * @return the validity of the password for the <code>Person</code>
	 */
	public boolean isValidPassword(String pw) {
		boolean valid = false;
		
		if (pw.compareTo(password)==0) {valid = true;}
		
		return valid;
		
	}
	
	public boolean isEmpty() {
		if (name.compareTo(new String())==0) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * The <code>Person</code>'s password
	 */
	private String password;
	/**
	 * The <code>Person</code>'s name
	 */
	private String name;
	/**
	 * The <code>Person</code>'s email
	 */
	private String email;
	/**
	 * The <code>Person</code>'s db record id
	 */
	private Long id;
}
