/*
 *	EasyScout Boy Scouts of America tracking software.
 *	http://www.easyscout.org/
 *
 *	Copyright (C) 2000 Conan C. Albrecht
 *	conan@warp.cx
 *
 *	This program is released under the GNU license so tech-savvy
 *	Boy Scouts and others can enhance the program for the use
 *	of all.  Please e-mail changes to my address above so I can
 *	reintegrate into the main program at http://www.easyscout.org/.
 *	This way, all users mutually benefit one another in the spirit of
 *	scouting.
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License
 *	as published by the Free Software Foundation; either version 2
 *	of the License, or (at your option) any later version.
 *
 * 	Any and all changes to the program code must be documented with
 *  date, author name and e-mail, and a short description.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package cx.warp.scout;

import java.util.*;
import java.io.*;

/** Holds session information for users.  There is one Session object per log that is opened. */
public class Session implements Serializable {
	
	static final long serialVersionUID = -3938281917555239739L;
	
	String z = Utils.getGUID();
	Troop troop = null;
	String page = "0";
	Scout scout = null;  // set only if this is a scout login
	boolean readonly = false; // if readonly
	boolean superuser = false;
	Date created = new Date();

	/** Constructor */
	public Session () {
	} //Session

	/** Returns the unique session id */
	public String getSessionID () {
		return  z;
	} //getSessionID


	/** Returns the unique session id (same result as getSessionID) */
	public String getZ () {
		return  z;
	} //getZ
	
	/** Sets the troop we are currently working on */
	public void setTroop(Troop troop) {
		this.troop = troop;
	}//setTroop
	
	/** Gets the troop we are currently working on */
	public Troop getTroop() {
		return troop;
	}//getTroop
	
	/** Sets the current page the user is on */
	public void setPage(String page) {
		this.page = page;
	}//setPage
	
	/** Returns the current page the user is on */
	public String getPage() {
		return page;
	}//page
	
	/** Returns whether this is a owner login (false means a scout login) */
	public boolean isOwner() {
		return (scout == null || superuser);
	}//isOwner
	
	/** Returns whether this is a scout login (false means owner/scoutmaster login) */
	public boolean isScout() {
		return (scout != null);
	}//isScout
	
	/** Sets the scout that is logged in */
	public void setScout(Scout scout) {
		this.scout = scout;
	}//scout
	
	/** Returns the scout that is logged in, if one is (null on owner/scoutmaster login) */
	public Scout getScout() {
		return scout;
	}//getScout
	
	/** Sets whether this session is read-only (initially false & write enabled) */
	public void setReadOnly(boolean readonly) {
		this.readonly = readonly;
	}//setReadOnly
	
	/** Returns whether this session is read-only */
	public boolean isReadOnly() {
		return (!isWrite());
	}//isReadOnly
	
	/** Returns whether this session is write-enabled. Opposite of isReadOnly(). */
	public boolean isWrite() {
		return (!readonly || superuser);
	}//isWrite
	
	/** Sets whether this session has superuser priviledges */
	public void setSuperUser(boolean root) {
		superuser = root;
	}//setSuperUser
	
	/** Returns whether this session has superuser priviledges */
	public boolean isSuperUser() {
		return superuser;
	}//isSuper
	
	/** Returns whether this session has superuser priviledges */
	public boolean isRoot() {
		return superuser;
	}//isSuper
	
	/** Returns the date the session was created */
	public Date getCreated() {
		return created;
	}//getCreated

}//Session class

