package it.micegroup.gestioneferie.pianificazioneferie.entity;

import java.io.Serializable;

import javax.validation.constraints.NotNull;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.FetchType;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.annotation.JsonBackReference;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.Getter;
import lombok.AllArgsConstructor;

import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Hibernate;
import java.util.Objects;

import it.micegroup.gestioneferie.pianificazioneferie.entity.DstatiRichiestaPfAmmtoKey;
import it.micegroup.gestioneferie.pianificazioneferie.entity.DpianificFerieAmmtoKey;

import it.micegroup.gestioneferie.libs.entity.BaseEntity;
import it.micegroup.voila2runtime.utils.EntityUtils;

@NoArgsConstructor

@Getter
@Setter
@Entity
@Table(name = "D_RICH_PIANIF_FERIE_AMMTO")
public class DrichPianifFerieAmmto extends BaseEntity implements Serializable {

	// Generated SERIAL VERSION UID
	private static final long serialVersionUID = 406039699L;

	@SuppressWarnings("unused")
	private static final Logger LOGGER = LogManager.getLogger(DrichPianifFerieAmmto.class);

	// ATTRIBUTES
	@NotNull

	@Column(name = "SEQU_ID_RICH_PIAN_FERIE_AMMTO", columnDefinition = "NUMBER(15)")
	private Long sequIdRichPianFerieAmmto;
	@NotNull

	@Column(name = "CODI_RICHIESTA_PIANO_FERIE", columnDefinition = "VARCHAR(50)")
	private String codiRichiestaPianoFerie;
	@NotNull

	@Column(name = "DESC_RICHIESTA_PIANO_FERIE", columnDefinition = "VARCHAR(250)")
	private String descRichiestaPianoFerie;
	@Column(name = "TEXT_NOTE", columnDefinition = "LONGTEXT")
	private String textNote;
	@NotNull

	@Column(name = "FK_PIANIFIC_FERIE_AMMTO", columnDefinition = "NUMBER(15)")
	private Long fkPianificFerieAmmto;
	@NotNull

	@Column(name = "FK_STATO_RICHIESTA_PF_AMMTO", columnDefinition = "NUMBER(15)")
	private Long fkStatoRichiestaPfAmmto;
	@NotNull

	@Column(name = "FLAG_ELIMINATO", columnDefinition = "VARCHAR(1)")
	private String flagEliminato;
	@NotNull

	@Column(name = "UTENTE_ULTIMA_MODIFICA", columnDefinition = "VARCHAR(50)")
	private String utenteUltimaModifica;
	@NotNull

	@Column(name = "DATA_ULTIMA_MODIFICA", columnDefinition = "DATE")
	private Date dataUltimaModifica;
	@NotNull

	@Column(name = "DATA_INIZIO_RECORD", columnDefinition = "DATE")
	private Date dataInizioRecord;
	@NotNull

	@Column(name = "DATA_FINE_RECORD", columnDefinition = "DATE")
	private Date dataFineRecord;

	// IMPORTED PARENTS

	// CONSTRUCTORS
	public DrichPianifFerieAmmto(String objectKey) {
		super();
		setObjectKey(objectKey);
	}

	public DrichPianifFerieAmmto(DrichPianifFerieAmmtoKey drichPianifFerieAmmtoKey, Long sequIdRichPianFerieAmmto,
			String codiRichiestaPianoFerie, String descRichiestaPianoFerie, String textNote, Long fkPianificFerieAmmto,
			Long fkStatoRichiestaPfAmmto, String flagEliminato, String utenteUltimaModifica, Date dataUltimaModifica,
			Date dataInizioRecord, Date dataFineRecord) {
		super();

		this.drichPianifFerieAmmtoKey = drichPianifFerieAmmtoKey;

		this.sequIdRichPianFerieAmmto = sequIdRichPianFerieAmmto;
		this.codiRichiestaPianoFerie = codiRichiestaPianoFerie;
		this.descRichiestaPianoFerie = descRichiestaPianoFerie;
		this.textNote = textNote;
		this.fkPianificFerieAmmto = fkPianificFerieAmmto;
		this.fkStatoRichiestaPfAmmto = fkStatoRichiestaPfAmmto;
		this.flagEliminato = flagEliminato;
		this.utenteUltimaModifica = utenteUltimaModifica;
		this.dataUltimaModifica = dataUltimaModifica;
		this.dataInizioRecord = dataInizioRecord;
		this.dataFineRecord = dataFineRecord;
	}

	// CHILDREN

	// PARENTS
	@NotNull
	@ManyToOne(fetch = FetchType.LAZY)
	@JsonBackReference("theDstatiRichiestaPfAmmto")
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" }, allowSetters = true)
	private DstatiRichiestaPfAmmto theDstatiRichiestaPfAmmto;
	@NotNull
	@ManyToOne(fetch = FetchType.LAZY)
	@JsonBackReference("theDpianificFerieAmmto")
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" }, allowSetters = true)
	private DpianificFerieAmmto theDpianificFerieAmmto;

	// GETTER/SETTER
	/**
	 * @return the sequIdRichPianFerieAmmto
	 */
	public Long getSequIdRichPianFerieAmmto() {
		return this.sequIdRichPianFerieAmmto;
	}

	/**
	 * @param sequIdRichPianFerieAmmto to set
	 */
	public void setSequIdRichPianFerieAmmto(Long sequIdRichPianFerieAmmto) {
		this.sequIdRichPianFerieAmmto = sequIdRichPianFerieAmmto;
	}

	/**
	 * @return the codiRichiestaPianoFerie
	 */
	public String getCodiRichiestaPianoFerie() {
		return this.codiRichiestaPianoFerie;
	}

	/**
	 * @param codiRichiestaPianoFerie to set
	 */
	public void setCodiRichiestaPianoFerie(String codiRichiestaPianoFerie) {
		this.codiRichiestaPianoFerie = codiRichiestaPianoFerie;
	}

	/**
	 * @return the descRichiestaPianoFerie
	 */
	public String getDescRichiestaPianoFerie() {
		return this.descRichiestaPianoFerie;
	}

	/**
	 * @param descRichiestaPianoFerie to set
	 */
	public void setDescRichiestaPianoFerie(String descRichiestaPianoFerie) {
		this.descRichiestaPianoFerie = descRichiestaPianoFerie;
	}

	/**
	 * @return the textNote
	 */
	public String getTextNote() {
		return this.textNote;
	}

	/**
	 * @param textNote to set
	 */
	public void setTextNote(String textNote) {
		this.textNote = textNote;
	}

	/**
	 * @return the fkPianificFerieAmmto
	 */
	public Long getFkPianificFerieAmmto() {
		return this.fkPianificFerieAmmto;
	}

	/**
	 * @param fkPianificFerieAmmto to set
	 */
	public void setFkPianificFerieAmmto(Long fkPianificFerieAmmto) {
		this.fkPianificFerieAmmto = fkPianificFerieAmmto;
	}

	/**
	 * @return the fkStatoRichiestaPfAmmto
	 */
	public Long getFkStatoRichiestaPfAmmto() {
		return this.fkStatoRichiestaPfAmmto;
	}

	/**
	 * @param fkStatoRichiestaPfAmmto to set
	 */
	public void setFkStatoRichiestaPfAmmto(Long fkStatoRichiestaPfAmmto) {
		this.fkStatoRichiestaPfAmmto = fkStatoRichiestaPfAmmto;
	}

	/**
	 * @return the flagEliminato
	 */
	public String getFlagEliminato() {
		return this.flagEliminato;
	}

	/**
	 * @param flagEliminato to set
	 */
	public void setFlagEliminato(String flagEliminato) {
		this.flagEliminato = flagEliminato;
	}

	/**
	 * @return the utenteUltimaModifica
	 */
	public String getUtenteUltimaModifica() {
		return this.utenteUltimaModifica;
	}

	/**
	 * @param utenteUltimaModifica to set
	 */
	public void setUtenteUltimaModifica(String utenteUltimaModifica) {
		this.utenteUltimaModifica = utenteUltimaModifica;
	}

	/**
	 * @return the dataUltimaModifica
	 */
	public Date getDataUltimaModifica() {
		return this.dataUltimaModifica;
	}

	/**
	 * @param dataUltimaModifica to set
	 */
	public void setDataUltimaModifica(Date dataUltimaModifica) {
		this.dataUltimaModifica = dataUltimaModifica;
	}

	/**
	 * @return the dataInizioRecord
	 */
	public Date getDataInizioRecord() {
		return this.dataInizioRecord;
	}

	/**
	 * @param dataInizioRecord to set
	 */
	public void setDataInizioRecord(Date dataInizioRecord) {
		this.dataInizioRecord = dataInizioRecord;
	}

	/**
	 * @return the dataFineRecord
	 */
	public Date getDataFineRecord() {
		return this.dataFineRecord;
	}

	/**
	 * @param dataFineRecord to set
	 */
	public void setDataFineRecord(Date dataFineRecord) {
		this.dataFineRecord = dataFineRecord;
	}

	// CHILD GETTER/SETTER

	/// ADD CHILD

	// PARENT GETTER/SETTER
	/**
	 * @return the DstatiRichiestaPfAmmto
	 */
	@JsonProperty(access = Access.WRITE_ONLY)
	public DstatiRichiestaPfAmmto getTheDstatiRichiestaPfAmmto() {
		return theDstatiRichiestaPfAmmto;
	}

	/**
	 * @param aDstatiRichiestaPfAmmtoList to set
	 */
	public void setTheDstatiRichiestaPfAmmto(DstatiRichiestaPfAmmto aDstatiRichiestaPfAmmto) {
		theDstatiRichiestaPfAmmto = aDstatiRichiestaPfAmmto;
	}

	/**
	 * @return the DpianificFerieAmmto
	 */
	@JsonProperty(access = Access.WRITE_ONLY)
	public DpianificFerieAmmto getTheDpianificFerieAmmto() {
		return theDpianificFerieAmmto;
	}

	/**
	 * @param aDpianificFerieAmmtoList to set
	 */
	public void setTheDpianificFerieAmmto(DpianificFerieAmmto aDpianificFerieAmmto) {
		theDpianificFerieAmmto = aDpianificFerieAmmto;
	}

	// PARENT ID GETTER/SETTER
	/**
	 * Return the dstatiRichiestaPfAmmtoKey from theDstatiRichiestaPfAmmto.
	 * 
	 * @return dstatiRichiestaPfAmmtoKey from theDstatiRichiestaPfAmmto.
	 */
	@JsonProperty
	public DstatiRichiestaPfAmmtoKey getDstatiRichiestaPfAmmtoKey() {
		// If the parent entity object is null, then return null
		if (getTheDstatiRichiestaPfAmmto() == null) {
			return null;
		}
		// Return requested attribute
		return theDstatiRichiestaPfAmmto.getDstatiRichiestaPfAmmtoKey();
	}

	/**
	 * Return the dpianificFerieAmmtoKey from theDpianificFerieAmmto.
	 * 
	 * @return dpianificFerieAmmtoKey from theDpianificFerieAmmto.
	 */
	@JsonProperty
	public DpianificFerieAmmtoKey getDpianificFerieAmmtoKey() {
		// If the parent entity object is null, then return null
		if (getTheDpianificFerieAmmto() == null) {
			return null;
		}
		// Return requested attribute
		return theDpianificFerieAmmto.getDpianificFerieAmmtoKey();
	}

	// PARENT OBJECT TITLE
	/**
	 * Return the object title of theDstatiRichiestaPfAmmto.
	 * 
	 * @return the object title of theDstatiRichiestaPfAmmto.
	 */
	@JsonProperty
	public String getTheDstatiRichiestaPfAmmtoObjectTitle() {
		return getTheDstatiRichiestaPfAmmto() != null ? getTheDstatiRichiestaPfAmmto().getObjectTitle() : null;
	}

	/**
	 * Return the object title of theDpianificFerieAmmto.
	 * 
	 * @return the object title of theDpianificFerieAmmto.
	 */
	@JsonProperty
	public String getTheDpianificFerieAmmtoObjectTitle() {
		return getTheDpianificFerieAmmto() != null ? getTheDpianificFerieAmmto().getObjectTitle() : null;
	}

	// PARENT OBJECT KEY
	/**
	 * Return the object key of theDstatiRichiestaPfAmmto.
	 * 
	 * @return the object key of theDstatiRichiestaPfAmmto.
	 */
	@JsonProperty
	public String getTheDstatiRichiestaPfAmmtoObjectKey() {
		return getTheDstatiRichiestaPfAmmto() != null ? getTheDstatiRichiestaPfAmmto().getObjectKey() : null;
	}

	/**
	 * Set object key of theDstatiRichiestaPfAmmto.
	 * 
	 */
	@JsonProperty
	public void setTheDstatiRichiestaPfAmmtoObjectKey(String objectKey) {
		if (EntityUtils.isValueChanged(getTheDstatiRichiestaPfAmmtoObjectKey(), objectKey, false)) {
			DstatiRichiestaPfAmmto dstatiRichiestaPfAmmto = new DstatiRichiestaPfAmmto();
			dstatiRichiestaPfAmmto.setObjectKey(objectKey);
			setTheDstatiRichiestaPfAmmto(dstatiRichiestaPfAmmto);
		}
	}

	/**
	 * Return the object key of theDpianificFerieAmmto.
	 * 
	 * @return the object key of theDpianificFerieAmmto.
	 */
	@JsonProperty
	public String getTheDpianificFerieAmmtoObjectKey() {
		return getTheDpianificFerieAmmto() != null ? getTheDpianificFerieAmmto().getObjectKey() : null;
	}

	/**
	 * Set object key of theDpianificFerieAmmto.
	 * 
	 */
	@JsonProperty
	public void setTheDpianificFerieAmmtoObjectKey(String objectKey) {
		if (EntityUtils.isValueChanged(getTheDpianificFerieAmmtoObjectKey(), objectKey, false)) {
			DpianificFerieAmmto dpianificFerieAmmto = new DpianificFerieAmmto();
			dpianificFerieAmmto.setObjectKey(objectKey);
			setTheDpianificFerieAmmto(dpianificFerieAmmto);
		}
	}

	// IMPORTED PARENT OBJECT KEY

	// OPERATIONS

	// OBJECT KEY
	/**
	 * Restituisce l'identificativo della chiave in formato stringa. Ritorna
	 * conveniente nelle selezioni da lista.
	 * 
	 * @return L'identificativo della chiave in formato pk1||pk2||pk3...
	 */
	public String getObjectKey() {
		return getObjectKeyById(getDrichPianifFerieAmmtoKey());
	}

	public String getObjectKeyById(DrichPianifFerieAmmtoKey identification) {
		if (identification == null) {
			return null;
		}
		StringBuilder output = new StringBuilder();
		return output.toString();
	}

	/**
	 * Inizializza la parte identificativa del bean in base alla stringa tokenizzata
	 * da "||" fornita in input.
	 * 
	 * @param key L'identificativo della chiave in formato pk1||pk2||pk3...
	 */
	public void setObjectKey(String key) {
		if (key == null || key.trim().length() == 0) {
			return;
		}
		String[] array = StringUtils.splitByWholeSeparatorPreserveAllTokens(key, getRowIdFieldDelimiter());
		int ctr = 0;

		drichPianifFerieAmmtoKey = new DrichPianifFerieAmmtoKey();
	}

	// OBJECT TITLE
	public String getObjectTitle() {
		StringBuilder output = new StringBuilder();
		output.append(getCodiRichiestaPianoFerie());
		return output.toString();
	}

	// COMPOSITE PRIMARY KEY
	@EmbeddedId
	private DrichPianifFerieAmmtoKey drichPianifFerieAmmtoKey;

	// GETTER/SETTER CK
	/**
	 * @return the drichPianifFerieAmmtoKey
	 */
	public DrichPianifFerieAmmtoKey getDrichPianifFerieAmmtoKey() {
		return this.drichPianifFerieAmmtoKey;
	}

	/**
	 * @param drichPianifFerieAmmtoKey to set
	 */
	public void setDrichPianifFerieAmmtoKey(DrichPianifFerieAmmtoKey drichPianifFerieAmmtoKey) {
		this.drichPianifFerieAmmtoKey = drichPianifFerieAmmtoKey;
	}

	// COMPOSITE KEY CLASS

	// PREPERSIST
	public void syncCK() {
		if (drichPianifFerieAmmtoKey == null) {
			drichPianifFerieAmmtoKey = new DrichPianifFerieAmmtoKey();
		}
	}

	@PrePersist
	public void prePersist() {
		syncCK();
	}

	@PreUpdate
	public void PreUpdate() {
		syncCK();
	}

	// Equals / HashCode
	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o))
			return false;
		DrichPianifFerieAmmto that = (DrichPianifFerieAmmto) o;
		return drichPianifFerieAmmtoKey != null
				&& Objects.equals(drichPianifFerieAmmtoKey, that.drichPianifFerieAmmtoKey);
	}

	@Override
	public int hashCode() {
		return Objects.hash(drichPianifFerieAmmtoKey);
	}
}
