package kr.co.kihyun.beans.entity;

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class UserUser extends MoumiEntity<Long> implements HandySync {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6793419265856541569L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.NATIVE)
	private Long userUserId;

	@Persistent
	private String handyId;

	@Persistent(nullValue = NullValue.EXCEPTION)
	private String id;

	@Persistent(nullValue = NullValue.EXCEPTION)
	private String name;

	@Persistent
	private String mDept;

	@Persistent
	private UserPart userPart;

	@Persistent
	private boolean valid;

	public UserUser() {
	}

	public Long getId() {
		return this.userUserId;
	}

	public void setId(Long userUserId) {
		this.userUserId = userUserId;
	}

	public void setHandyId(String handyId) {
		this.handyId = handyId;
	}

	public String getHandyId() {
		return handyId;
	}

	public MUser getUser(PersistenceManager pm) {
		try {
			return pm.getObjectById(MUser.class, this.id);
		} catch (JDOObjectNotFoundException jonfe) {
			return null;
		}
	}

	public void setUser(MUser id) {
		if (id == null)
			this.id = null;
		else
			this.id = id.getId();
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public MDept getDept(PersistenceManager pm) {
		try {
			return pm.getObjectById(MDept.class, this.mDept);
		} catch (JDOObjectNotFoundException jonfe) {
			return null;
		}
	}

	public void setDept(MDept mDept) {
		if (mDept == null)
			this.mDept = null;
		else
			this.mDept = mDept.getId();
	}

	public UserPart getPart() {
		return this.userPart;
	}

	public void setPart(UserPart part) {
		this.userPart = part;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	public boolean isValid() {
		return valid;
	}

	public UserUser(MUser user, String name, MDept mDept, UserPart userPart) {
		this.setUser(user);
		this.setName(name);
		this.setDept(mDept);
		this.setPart(userPart);
		this.setValid(true);
	}

}
