package com.bankaudit.process.model;

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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name="audit_plan")
public class AuditPlan implements Serializable {

/*	Table: audit_plan
	---------------------

	Column Information 
	----------------------

	Field                   Type         Collation          Null    Key     Default            Extra                        Privileges                       Comment  
	----------------------  -----------  -----------------  ------  ------  -----------------  ---------------------------  -------------------------------  ---------
	legal_entity_code       int(2)       (NULL)             NO      PRI     (NULL)                                          select,insert,update,references           
	audit_type_code         varchar(20)  latin1_swedish_ci  NO      PRI     (NULL)                                          select,insert,update,references           
	plan_id                 varchar(20)  latin1_swedish_ci  NO      PRI     (NULL)                                          select,insert,update,references           
	plan_start_date         date         (NULL)             NO              (NULL)                                          select,insert,update,references           
	plan_end_date           date         (NULL)             NO              (NULL)                                          select,insert,update,references           
	status                  varchar(20)  latin1_swedish_ci  NO              (NULL)                                          select,insert,update,references           
	maker                   varchar(20)  latin1_swedish_ci  NO              (NULL)                                          select,insert,update,references           
	maker_timestamp         timestamp    (NULL)             NO              CURRENT_TIMESTAMP  on update CURRENT_TIMESTAMP  select,insert,update,references           
	checker                 varchar(20)  latin1_swedish_ci  YES             (NULL)                                          select,insert,update,references           
	checker_timestamp       timestamp    (NULL)             YES             (NULL)                                          select,insert,update,references           
	businessdate_timestamp  timestamp    (NULL)             YES             (NULL)                                          select,insert,update,references           
	sysdate_timestamp       timestamp    (NULL)    
*/
	private final static String DEFAULT_VALUE = "N";
	
	@Id
	@Column(name="legal_entity_code")
	private Integer legalEntityCode;
	
	@Id
	@Column(name="audit_type_code")
	private String auditTypeCode;
	
	@Id
	@Column(name="plan_id")
	private String planId;
	
	@Column(name="planner_unit_code")
	private String plannerUnitCode;
	
	@Column(name="plan_type",nullable=true)
	private String planType;

	@Column(name="plan_start_date")
	private Date planStartDate;
	
	@Column(name="plan_end_date")
	private Date planEndDate;
	
	@Column(name="status")
	private String status;
	
	@Column(name="maker")
	private String maker;
	
	@Column(name="maker_timestamp")
	private Date makerTimestamp;
	
	@Column(name="checker")
	private String checker;
	
	@Column(name="checker_timestamp")
	private Date checkerTimestamp;
	
	@Column(name="businessdate_timestamp")
	private Date businessdateTimestamp;
	
	@Column(name = "auth_rej_remarks")
	private String authRejRemarks;
	
	@Column(name="sysdate_timestamp")
	private Date sysdateTimestamp;
	
	private transient String plannerUnitName;
	private transient String plannerLevelCode;
	private transient String plannerLevelDesc;
	

	@LazyCollection(LazyCollectionOption.FALSE)
	 @OneToMany()
	    @JoinColumns({ 
	        @JoinColumn(name = "legal_entity_code", referencedColumnName = "legal_entity_code"), 
	        @JoinColumn(name = "audit_type_code", referencedColumnName = "audit_type_code"), 
	        @JoinColumn(name = "plan_id", referencedColumnName = "plan_id"),
	    })
	private List<AuditSchedule> auditSchedules;

	public AuditPlan() {
	}

	
	
	/**
	 * @return the authRejRemarks
	 */
	public String getAuthRejRemarks() {
		return authRejRemarks;
	}



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



	/**
	 * @param legalEntityCode
	 * @param auditTypeCode
	 * @param planId
	 * @param planStartDate
	 * @param planEndDate
	 * @param status
	 * @param maker
	 * @param makerTimestamp
	 * @param checker
	 * @param checkerTimestamp
	 * @param businessdateTimestamp
	 * @param sysdateTimestamp
	 * @param auditSchedules
	 */
	public AuditPlan(AuditPlanWrk auditPlanWrk) {
		super();
		this.legalEntityCode = auditPlanWrk.getLegalEntityCode();
		this.auditTypeCode = auditPlanWrk.getAuditTypeCode();
		this.authRejRemarks = auditPlanWrk.getAuthRejRemarks();
		this.planId = auditPlanWrk.getPlanId();
		this.planType = auditPlanWrk.getPlanType();
		this.plannerUnitCode = auditPlanWrk.getPlannerUnitCode();
		this.planStartDate = auditPlanWrk.getPlanStartDate();
		this.planEndDate = auditPlanWrk.getPlanEndDate();
		this.status = auditPlanWrk.getStatus();
		this.maker = auditPlanWrk.getMaker();
		this.makerTimestamp = auditPlanWrk.getMakerTimestamp();
		this.checker = auditPlanWrk.getChecker();
		this.checkerTimestamp = auditPlanWrk.getCheckerTimestamp();
		this.businessdateTimestamp = auditPlanWrk.getBusinessdateTimestamp();
		this.sysdateTimestamp = auditPlanWrk.getSysdateTimestamp();
		if(auditPlanWrk.getAuditScheduleWrks()!=null){
			this.auditSchedules = new ArrayList<AuditSchedule>();
			for (AuditScheduleWrk auditScheduleWrk : auditPlanWrk.getAuditScheduleWrks()) {
				this.auditSchedules.add(new AuditSchedule(auditScheduleWrk));
			}
		}
	}



	/**
	 * @return the legalEntityCode
	 */
	public Integer getLegalEntityCode() {
		return legalEntityCode;
	}

	/**
	 * @param legalEntityCode the legalEntityCode to set
	 */
	public void setLegalEntityCode(Integer legalEntityCode) {
		this.legalEntityCode = legalEntityCode;
	}

	/**
	 * @return the auditTypeCode
	 */
	public String getAuditTypeCode() {
		return auditTypeCode;
	}

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

	/**
	 * @return the planId
	 */
	public String getPlanId() {
		return planId;
	}

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

	public String getPlannerUnitCode() {
		return plannerUnitCode;
	}



	public void setPlannerUnitCode(String plannerUnitCode) {
		this.plannerUnitCode = plannerUnitCode;
	}



	public String getPlanType() {
		return planType;
	}



	public void setPlanType(String planType) {
		if(planType==null) {
			this.planType=DEFAULT_VALUE;
		}else {
		    this.planType = planType;
		}
	}


	/**
	 * @return the planStartDate
	 */
	public Date getPlanStartDate() {
		return planStartDate;
	}

	/**
	 * @param planStartDate the planStartDate to set
	 */
	public void setPlanStartDate(Date planStartDate) {
		this.planStartDate = planStartDate;
	}

	/**
	 * @return the planEndDate
	 */
	public Date getPlanEndDate() {
		return planEndDate;
	}

	/**
	 * @param planEndDate the planEndDate to set
	 */
	public void setPlanEndDate(Date planEndDate) {
		this.planEndDate = planEndDate;
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

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

	/**
	 * @return the maker
	 */
	public String getMaker() {
		return maker;
	}

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

	/**
	 * @return the makerTimestamp
	 */
	public Date getMakerTimestamp() {
		return makerTimestamp;
	}

	/**
	 * @param makerTimestamp the makerTimestamp to set
	 */
	public void setMakerTimestamp(Date makerTimestamp) {
		this.makerTimestamp = makerTimestamp;
	}

	/**
	 * @return the checker
	 */
	public String getChecker() {
		return checker;
	}

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

	/**
	 * @return the checkerTimestamp
	 */
	public Date getCheckerTimestamp() {
		return checkerTimestamp;
	}

	/**
	 * @param checkerTimestamp the checkerTimestamp to set
	 */
	public void setCheckerTimestamp(Date checkerTimestamp) {
		this.checkerTimestamp = checkerTimestamp;
	}

	/**
	 * @return the businessdateTimestamp
	 */
	public Date getBusinessdateTimestamp() {
		return businessdateTimestamp;
	}

	/**
	 * @param businessdateTimestamp the businessdateTimestamp to set
	 */
	public void setBusinessdateTimestamp(Date businessdateTimestamp) {
		this.businessdateTimestamp = businessdateTimestamp;
	}

	/**
	 * @return the sysdateTimestamp
	 */
	public Date getSysdateTimestamp() {
		return sysdateTimestamp;
	}

	/**
	 * @param sysdateTimestamp the sysdateTimestamp to set
	 */
	public void setSysdateTimestamp(Date sysdateTimestamp) {
		this.sysdateTimestamp = sysdateTimestamp;
	}

	

	public String getPlannerUnitName() {
		return plannerUnitName;
	}



	public void setPlannerUnitName(String plannerUnitName) {
		this.plannerUnitName = plannerUnitName;
	}



	public String getPlannerLevelCode() {
		return plannerLevelCode;
	}



	public void setPlannerLevelCode(String plannerLevelCode) {
		this.plannerLevelCode = plannerLevelCode;
	}



	public String getPlannerLevelDesc() {
		return plannerLevelDesc;
	}



	public void setPlannerLevelDesc(String plannerLevelDesc) {
		this.plannerLevelDesc = plannerLevelDesc;
	}



	/**
	 * @return the auditSchedules
	 */
	public List<AuditSchedule> getAuditSchedules() {
		return auditSchedules;
	}

	/**
	 * @param auditSchedules the auditSchedules to set
	 */
	public void setAuditSchedules(List<AuditSchedule> auditSchedules) {
		this.auditSchedules = auditSchedules;
	}






	
	 

	
}
