package kr.co.kihyun.beans.entity;

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

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.jdo.annotations.*;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class UserPart extends MoumiEntity<String> implements HandySync {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3443962381789084300L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.UUIDHEX)
	private String id;

	@Persistent
	private String handyId;

	@Persistent
	private String name;

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

	@Persistent(customValueStrategy = "timestamp", nullValue = NullValue.EXCEPTION)
	private Date regDate;

	@Persistent
	private String des;
        
        @Persistent(customValueStrategy = "timestamp", nullValue = NullValue.DEFAULT)
	private Date modDate = new Date();

	@Persistent(nullValue = NullValue.DEFAULT)
	private String useYn = "Y";

	@Persistent(mappedBy = "userPart")
	private List<UserDept> userDepts = new ArrayList<UserDept>();

	@Persistent(mappedBy = "userPart")
	private List<UserUser> userUsers = new ArrayList<UserUser>();

	public UserPart() {
	}

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

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

	public Date getRegDate() {
		return this.regDate;
	}

	public void setRegDate(Date d) {
		this.regDate = d;
	}

	public String getDescription() {
		return this.des;
	}

	public void setDescription(String description) {
		this.des = description;
	}

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

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

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

	public String getHandyId() {
		return handyId;
	}

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

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
        
        public Date getModDate() {
            return modDate;
        }

        public void setModDate(Date modDate) {
            this.modDate = modDate;
        }

        public String getUseYn() {
            return useYn;
        }

        public void setUseYn(String useYn) {
            this.useYn = useYn;
        }

	public List<UserUser> getUserUsers() {
		return this.userUsers;
	}

	public List<UserDept> getUserDepts() {
		return this.userDepts;
	}

	public UserPart(String name, MUser user, String description) {
		this.setName(name);
		this.setRegDate(new Date());
		this.setUser(user);
		this.setDescription(description);
		this.setRegDate(new Date(System.currentTimeMillis()));
	}
}
