package sfs.cluster.lobby.data;

/**
 * A Reservation object is created when a user is joining a game room an game node.
 * The Reservation allows the user to join the game server within a certain amount of time (in seconds).
 */
public class RoomReservation
{
	long creationTime;			// unix time of the creation of this object
	long expiryTime;			// unix time of the expiry of the reservation
	String owner;				// name of the owner of the reservation
	int targetRoomId;			// the target room of the reservation
	
	/**
	 * Create a Reservation
	 * 
	 * @param owner				the user name
	 * @param targetRoomId		the id of the room
	 * @param expiryTime		how many seconds this reservation will last
	 */
	public RoomReservation(String owner, int targetRoomId, int expiryTime)
    {
		this.owner = owner;
		this.targetRoomId = targetRoomId;
		this.creationTime = System.currentTimeMillis();
		this.expiryTime = this.creationTime + (expiryTime * 1000);
	}
	
	public boolean isExpired()
	{
		return expiryTime < System.currentTimeMillis();
	}
	
	@Override
	public String toString()
	{
	    return String.format("Reservation for user: %s, to room ID: %s. Expired = %s", owner, targetRoomId, isExpired());
	}



	public long getCreationTime()
    {
    	return creationTime;
    }



	public long getExpiryTime()
    {
    	return expiryTime;
    }



	public String getOwner()
    {
    	return owner;
    }



	public int getTargetRoomId()
    {
    	return targetRoomId;
    }
	
	
}
