package kr.go.neis;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class ApproveMaster implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5314568451003294315L;
	private static final Logger LOG = LoggerFactory.getLogger(ApproveMaster.class);

	@PrimaryKey
	private String ssubbSysCode = "HIS";

	@PrimaryKey
	private String doctKndCode = "D83";

	@PrimaryKey
	private String schulCrseScCode = "4";

	@Persistent
	private String doctNm;

	@Persistent
	private int prsrvPrd = 30;

	@Persistent
	private int keyFgr = 1;

	@Persistent
	private String inqrCharsNm;

	@Persistent
	private boolean useYn = true;

	@Persistent
	private String confmBusnScrinUrl;

	@Persistent
	private String confmBusnPopupUrl;

	@Persistent
	private String updid = "SYSTEM";

	@Persistent
	private String mdfcYmd;

	public ApproveMaster(String docName) {
		this.setDoctNm(docName);
		this.setMdfcYmd(new Date());
	}

	public final String getSsubbSysCode() {
		return ssubbSysCode;
	}

	public final void setSsubbSysCode(String ssubbSysCode) {
		this.ssubbSysCode = ssubbSysCode;
	}

	public final String getDoctKndCode() {
		return doctKndCode;
	}

	public final void setDoctKndCode(String doctKndCode) {
		this.doctKndCode = doctKndCode;
	}

	public final String getSchulCrseScCode() {
		return schulCrseScCode;
	}

	public final void setSchulCrseScCode(String schulCrseScCode) {
		this.schulCrseScCode = schulCrseScCode;
	}

	public final String getDoctNm() {
		return doctNm;
	}

	public final void setDoctNm(String doctNm) {
		this.doctNm = doctNm;
	}

	public final int getPrsrvPrd() {
		return prsrvPrd;
	}

	public final void setPrsrvPrd(int prsrvPrd) {
		this.prsrvPrd = prsrvPrd;
	}

	public final int getKeyFgr() {
		return keyFgr;
	}

	public final void setKeyFgr(int keyFgr) {
		this.keyFgr = keyFgr;
	}

	public final String getInqrCharsNm() {
		return inqrCharsNm;
	}

	public final void setInqrCharsNm(String inqrCharsNm) {
		this.inqrCharsNm = inqrCharsNm;
	}

	public final boolean isUseYn() {
		return useYn;
	}

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

	public final String getConfmBusnScrinUrl() {
		return confmBusnScrinUrl;
	}

	public final void setConfmBusnScrinUrl(String confmBusnScrinUrl) {
		this.confmBusnScrinUrl = confmBusnScrinUrl;
	}

	public final String getConfmBusnPopupUrl() {
		return confmBusnPopupUrl;
	}

	public final void setConfmBusnPopupUrl(String confmBusnPopupUrl) {
		this.confmBusnPopupUrl = confmBusnPopupUrl;
	}

	public final String getUpdid() {
		return updid;
	}

	public final void setUpdid(String updid) {
		this.updid = updid;
	}

	public final Date getMdfcYmd() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		try {
			return sdf.parse(this.mdfcYmd);
		} catch (ParseException e) {
			LOG.error("{} has invalid date format : {}", this, this.mdfcYmd);
			return null;
		}
	}

	public final void setMdfcYmd(Date mdfcYmd) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		this.mdfcYmd = sdf.format(mdfcYmd);
	}

	public static class PK implements Serializable {

		/**
		 * 
		 */
		private static final long serialVersionUID = -8406765554932443039L;

		public String ssubbSysCode;

		public String doctKndCode;

		public String schulCrseScCode;

		public PK() {
		}

		public boolean equals(Object obj) {
			if (obj != null && (obj instanceof PK)) {
				PK c = (PK) obj;
				return ssubbSysCode.equals(c.ssubbSysCode) && doctKndCode.equals(c.doctKndCode)
						&& schulCrseScCode.equals(c.schulCrseScCode);
			}
			return false;
		}

		public int hashCode() {
			return this.ssubbSysCode.hashCode() ^ this.doctKndCode.hashCode() ^ this.schulCrseScCode.hashCode();
		}

		public String toString() {
			return new StringBuilder(100).append(this.getClass().getName()).append("::").append(this.ssubbSysCode)
					.append("::").append(this.doctKndCode).append("::").append(this.schulCrseScCode).toString();
		}
	}
}
