package com.dragonsoft.tryapp.common;

import java.io.Serializable;

/**
 * Identifies a user across all parts of the system. Note that there is 
 * a difference between this class and UserCredentials. An instance of this 
 * class would be used to identify a user part of a group, such as all the 
 * users enrolled in a course. 
 * An instance of UserCredentials would be used to identify the user that 
 * is trying to perform an action, and contains more detailed information.
 */
public class TryUser implements Serializable {

    /**
     * The user's last name.
     */
    private String strLastName;

    /**
     * The user's first name.
     */
    private String strFirstName;

    /**
     * The type of user.
     */
    private String strTryUserLevel;

    /**
     * The Credentials associated with the User
     */
    private UserCredentials credentials;
    /**
     * Creates a new instance to represent a user.
     * 
     * @param    tryUsername     the user's username
     * @param    lastName        the user's last name
     * @param    firstName       the user's first name
     * @param    tryUserLevel    the type of user
     */
    public TryUser(String lastName, String firstName,UserCredentials creds) {
        this.strLastName = lastName;
        this.strFirstName = firstName;
    }

    /**
     * Returns the user's username.
     * 
     * @return    the user's username
     */
    public String getTryUsername() {
        return credentials.getUsername();
    }

    /**
     * Returns the user's last name.
     * 
     * @return    the user's last name
     */
    public String getLastName() {
        return (strLastName);
    }

    /**
     * Returns the user's first name.
     * 
     * @return    the user's first name
     */
    public String getFirstName() {
        return (strFirstName);
    }

    /**
     * Returns the type of user.
     * 
     * @return    the type of user
     */
    public String getTryUserLevel() {
        return (strTryUserLevel);
    }

    /**
     * Returns true if this instance represents the same user.
     * 
     * @param    obj    the object to compare to
     * 
     * @return    true if this instance represents the same user
     */
    public boolean equals(Object obj) {

        boolean returnValue = false;

        if (obj instanceof TryUser) {
            TryUser targetInstance = (TryUser) obj;

            if (credentials.getUsername().equals(targetInstance.getTryUsername())) {
                returnValue = true;
            }
        }

        return (returnValue);
    }

    /**
     * Returns the hash code for this object.
     * 
     * @return    the hash code for this object
     */
    public int hashCode() {
        return (credentials.getUsername().hashCode());
    }

} // TryUser