package kcg.faics.cmmn.vo;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * 메뉴 VO.
 * 
 * @author kimnomin
 *
 */
public class MenuVO {
	/**
	 * 식별자.
	 */
	private int id;
	/**
	 * 메뉴명.
	 */
	private String name;
	/**
	 * 영어 메뉴명.
	 */
	private String engName;
	/**
	 * 상위 메뉴 식별자.
	 */
	private int parent;
	/**
	 * 메뉴 깊이.
	 */
	private int depth;
	/**
	 * URL.
	 */
	private String url;
	/**
	 * URI. (쿼리 포함)
	 */
	private String uri;
	/**
	 * 메뉴 위치.
	 */
	private String menuPosition;
	/**
	 * 사용여부.
	 */
	private String visible;
	/**
	 * 메뉴 그룹.
	 */
	private String urlGroup;
	/**
	 * 페이지 내 하위메뉴 표현여부.
	 */
	private String subVisible;
	/**
	 * Role 레벨.
	 */
	private int roleLevel;
	/**
	 * URL 호출시 사용할 GET 파라미터 문자열.
	 */
	private String urlQuery;
	/**
	 * 게시판 ID. (공용뷰를 사용하는 페이지만 적용)
	 */
	private String boardId;
	/**
	 * 메뉴를 조회할 윈도우창 대상(HTML A태그의 TARGET 속성).
	 */
	private String windowTarget;
	/**
	 * 하위메뉴 목록.
	 */
	private List<MenuVO> subMenu = new ArrayList<MenuVO>();
	/**
	 * 사용자 ID.
	 */
	private String userId;
	/**
	 * 사용자 구분.
	 */
	private int userType;

  private int maxLevel;

  public int getMaxLevel() {
    return maxLevel;
  }

  public void setMaxLevel(int maxLevel) {
    this.maxLevel = maxLevel;
  }

  /**
	 * @return the id
	 */
	public final int getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public final void setId(final int id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public final String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public final void setName(final String name) {
		this.name = name;
	}

	/**
	 * @return the engName
	 */
	public final String getEngName() {
		return engName;
	}

	/**
	 * @param engName
	 *            the engName to set
	 */
	public final void setEngName(final String engName) {
		this.engName = engName;
	}

	/**
	 * @return the parent
	 */
	public final int getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public final void setParent(final int parent) {
		this.parent = parent;
	}

	/**
	 * @return the depth
	 */
	public final int getDepth() {
		return depth;
	}

	/**
	 * @param depth
	 *            the depth to set
	 */
	public final void setDepth(final int depth) {
		this.depth = depth;
	}

	/**
	 * @return the url
	 */
	public final String getUrl() {
		return url;
	}

	/**
	 * @param url
	 *            the url to set
	 */
	public final void setUrl(final String url) {
		this.url = url;
		this.makeUri();
	}

	/**
	 * @return the uri
	 */
	public final String getUri() {
		return uri;
	}

	/**
	 * Uri를 생성한다.
	 */
	public void makeUri() {
		String uri = "#";
		String qry = "";
		if (StringUtils.isNotBlank((this.getUrl()))) {
			uri = "";
			
			if (StringUtils.isNotBlank((this.getUrlGroup()))) {
				uri += this.getUrlGroup();
			}
			uri += this.getUrl();
			
			if (StringUtils.isNotBlank((this.getBoardId()))) {
				qry = "?id=" + this.getBoardId();
			}
			if (StringUtils.isNotBlank((this.getUrlQuery()))) {
				if (StringUtils.isBlank(qry)) {
					qry += "?";
				} else {
					qry += "&";
				}
				qry += this.getUrlQuery();
			}
			if (StringUtils.isNoneBlank(uri) && !"/".equals(uri.substring(0, 1))) {
				uri = "/" + uri;
			}
			
			uri += qry;
		}

		this.setUri(uri);
	}

	/**
	 * @param uri
	 *            the uri to set
	 */
	public final void setUri(final String uri) {
		this.uri = uri;
	}

	/**
	 * @return the menuPosition
	 */
	public final String getMenuPosition() {
		return menuPosition;
	}

	/**
	 * @param menuPosition
	 *            the menuPosition to set
	 */
	public final void setMenuPosition(final String menuPosition) {
		this.menuPosition = menuPosition;
	}

	/**
	 * @return the visible
	 */
	public final String getVisible() {
		return visible;
	}

	/**
	 * @param visible
	 *            the visible to set
	 */
	public final void setVisible(final String visible) {
		this.visible = visible;
	}

	/**
	 * @return the urlGroup
	 */
	public final String getUrlGroup() {
		return urlGroup;
	}

	/**
	 * @param urlGroup
	 *            the urlGroup to set
	 */
	public final void setUrlGroup(final String urlGroup) {
		this.urlGroup = urlGroup;
		this.makeUri();
	}

	/**
	 * @return the subVisible
	 */
	public final String getSubVisible() {
		return subVisible;
	}

	/**
	 * @param subVisible
	 *            the subVisible to set
	 */
	public final void setSubVisible(final String subVisible) {
		this.subVisible = subVisible;
	}

	/**
	 * @return the roleLevel
	 */
	public final int getRoleLevel() {
		return roleLevel;
	}

	/**
	 * @param roleLevel
	 *            the roleLevel to set
	 */
	public final void setRoleLevel(final int roleLevel) {
		this.roleLevel = roleLevel;
	}

	/**
	 * @return the windowTarget
	 */
	public final String getWindowTarget() {
		return windowTarget;
	}

	/**
	 * @param windowTarget
	 *            the windowTarget to set
	 */
	public final void setWindowTarget(final String windowTarget) {
		this.windowTarget = windowTarget;
	}

	/**
	 * @return the subMenu
	 */
	public final List<MenuVO> getSubMenu() {
		return subMenu;
	}

	/**
	 * @param subMenu
	 *            the subMenu to set
	 */
	public final void setSubMenu(final List<MenuVO> subMenu) {
		this.subMenu = subMenu;
	}

	/**
	 * @return the urlQuery
	 */
	public final String getUrlQuery() {
		return urlQuery;
	}

	/**
	 * @param urlQuery
	 *            the urlQuery to set
	 */
	public final void setUrlQuery(final String urlQuery) {
		this.urlQuery = urlQuery;
		this.makeUri();
	}

	/**
	 * @return the boardId
	 */
	public final String getBoardId() {
		return boardId;
	}

	/**
	 * @param boardId
	 *            the boardId to set
	 */
	public final void setBoardId(final String boardId) {
		this.boardId = boardId;
		this.makeUri();
	}

	/**
	 * @return the userId
	 */
	public final String getUserId() {
		return userId;
	}

	/**
	 * @param userId
	 *            the userId to set
	 */
	public final void setUserId(final String userId) {
		this.userId = userId;
	}

	/**
	 * @return the userType
	 */
	public final int getUserType() {
		return userType;
	}

	/**
	 * @param userType
	 *            the userType to set
	 */
	public final void setUserType(final int userType) {
		this.userType = userType;
	}

}
