/*
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.ajah.user;

import com.ajah.util.Identifiable;

/**
 * Basic implementations of UserType.
 * 
 * @author Eric F. Savage <code@efsavage.com>
 * 
 */
public enum UserType implements Identifiable<String> {

	/**
	 * Regular user, should be the default.
	 */
	NORMAL("1", "Normal", "Normal", "Normal");

	/**
	 * Finds a UserType that matches the id on id, name, or name().
	 * 
	 * @param id
	 *            Value to match against id, name, or name()
	 * @return Matching UserType, or null.
	 */
	public static UserType get(final String id) {
		for (final UserType type : values()) {
			if (type.getId().equals(id) || type.getCode().equals(id) || type.name().equals(id)) {
				return type;
			}
		}
		return null;
	}

	private final String id;
	private final String code;
	private final String name;
	private final String description;

	private UserType(final String id, final String code, final String name, final String description) {
		this.id = id;
		this.code = code;
		this.name = name;
		this.description = description;
	}

	/**
	 * The short, display-friendly code of the type. If no code is applicable,
	 * it should be an alias for the ID.
	 * 
	 * @return The short, display-friendly code of the type. Cannot be null.
	 */
	public String getCode() {
		return this.code;
	}

	/**
	 * The display-friendly description of the type.
	 * 
	 * @return The display-friendly description of the type. May be null.
	 */
	public String getDescription() {
		return this.description;
	}

	/**
	 * The internal ID of the type.
	 * 
	 * @return The internal ID of the type. Cannot be null.
	 */
	@Override
	public String getId() {
		return this.id;
	}

	/**
	 * The display-friendly name of the type. If no name is applicable, it
	 * should be an alias for the ID or code.
	 * 
	 * @return The display-friendly name of the type. Cannot be null.
	 */
	public String getName() {
		return this.name;
	}

	@Override
	public void setId(final String id) {
		throw new UnsupportedOperationException();
	}

}

@@ -845,16 +845,184 @@
 ing%3E %7B%0A%0A
+%09/**%0A%09 * Bot user, has no permissions except those explicitly assigned to it.%0A%09 */%0A%09BOT(%220%22, %22Bot%22, %22Bot User%22, %22Bot user, has no implicit permissions.%22, false, true),%0A
 %09/**%0A%09 *
@@ -1086,32 +1086,37 @@
 Normal%22, %22Normal
+ User
 %22, %22Normal%22);%0A%0A%09
@@ -1109,17 +1109,213 @@
  %22Normal
-%22
+ user, has default set of permissions.%22, false, false),%0A%09/**%0A%09 * Super (root) user, has all permissions.%0A%09 */%0A%09SUPER_USER(%222%22, %22Super%22, %22Super User%22, %22Super user, has all permissions.%22, true, false
 );%0A%0A%09/**
@@ -1840,16 +1840,82 @@
 ription;
+%0A%09private final boolean superUser;%0A%09private final boolean botUser;
 %0A%0A%09priva
@@ -2005,16 +2005,64 @@
 cription
+, final boolean superUser, final boolean botUser
 ) %7B%0A%09%09th
@@ -2139,32 +2139,88 @@
  = description;%0A
+%09%09this.superUser = superUser;%0A%09%09this.botUser = botUser;%0A
 %09%7D%0A%0A%09/**%0A%09 * The
@@ -3171,10 +3171,626 @@
 ();%0A%09%7D%0A%0A
+%09/**%0A%09 * Returns if this user type is a super user, meaning it has full access and%0A%09 * all permissions. This is similar to being a root or administrator user.%0A%09 * %0A%09 * @return the superUser True if the user is a super user.%0A%09 */%0A%09public boolean isSuperUser() %7B%0A%09%09return this.superUser;%0A%09%7D%0A%0A%09/**%0A%09 * Returns if this user type is a bot user, meaning it probably has a single%0A%09 * purpose related to automation. It has no default permissions, including%0A%09 * being able to log in, and must specifically assigned any access levels.%0A%09 * %0A%09 * @return the botUser%0A%09 */%0A%09public boolean isBotUser() %7B%0A%09%09return this.botUser;%0A%09%7D%0A%0A
 %7D%0A

Add additional user types