package it.micegroup.gestioneferie.configurazionepf.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.Id;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import java.util.Collection;
import java.util.ArrayList;
import javax.persistence.OneToMany;
import javax.persistence.CascadeType;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.ToString;

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

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.libs.entity.BaseEntity;
import it.micegroup.voila2runtime.utils.EntityUtils;

@NoArgsConstructor

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

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

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

	// ATTRIBUTES
	@Id

	@Column(name = "SEQU_ID_CONFIG_PA_PIANO_FERIE", columnDefinition = "NUMBER(15)")
	private Long sequIdConfigPaPianoFerie;
	@NotNull

	@Column(name = "CODI_CONFIG_PA_PIANO_FERIE", columnDefinition = "VARCHAR(50)")
	private String codiConfigPaPianoFerie;
	@NotNull

	@Column(name = "DESC_CONFIG_PA_PIANO_FERIE", columnDefinition = "VARCHAR(250)")
	private String descConfigPaPianoFerie;
	@NotNull

	@Column(name = "FK_AMMINISTRAZIONE_PK", columnDefinition = "NUMBER(15)")
	private Long fkAmministrazionePk;
	@NotNull

	@Column(name = "FK_TIPO_ORGANIGRAMMA", columnDefinition = "NUMBER(15)")
	private Long fkTipoOrganigramma;
	@NotNull

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

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

	@Column(name = "FLAG_ELIMINATO", columnDefinition = "VARCHAR(1)")
	private String flagEliminato;
	@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 DconfigPaPianiFerie(String objectKey) {
		super();
		setObjectKey(objectKey);
	}

	public DconfigPaPianiFerie(String codiConfigPaPianoFerie, String descConfigPaPianoFerie, Long fkAmministrazionePk,
			Long fkTipoOrganigramma, Date dataUltimaModifica, String utenteUltimaModifica, String flagEliminato,
			Date dataInizioRecord, Date dataFineRecord, Long sequIdConfigPaPianoFerie) {
		super();

		this.codiConfigPaPianoFerie = codiConfigPaPianoFerie;
		this.descConfigPaPianoFerie = descConfigPaPianoFerie;
		this.fkAmministrazionePk = fkAmministrazionePk;
		this.fkTipoOrganigramma = fkTipoOrganigramma;
		this.dataUltimaModifica = dataUltimaModifica;
		this.utenteUltimaModifica = utenteUltimaModifica;
		this.flagEliminato = flagEliminato;
		this.dataInizioRecord = dataInizioRecord;
		this.dataFineRecord = dataFineRecord;
		this.sequIdConfigPaPianoFerie = sequIdConfigPaPianoFerie;
	}

	// CHILDREN
	@JsonProperty(access = Access.WRITE_ONLY)
	@JsonManagedReference("theDconfigPaPianiFerie")
	@OneToMany(mappedBy = "theDconfigPaPianiFerie", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@ToString.Exclude
	private Collection<DpercAutPianFerieH> theDpercAutPianFerieH = new ArrayList<>();

	@JsonProperty(access = Access.WRITE_ONLY)
	@JsonManagedReference("theDconfigPaPianiFerie")
	@OneToMany(mappedBy = "theDconfigPaPianiFerie", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@ToString.Exclude
	private Collection<DconfigPaPfUoH> theDconfigPaPfUoH = new ArrayList<>();

	// PARENTS

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

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

	/**
	 * @return the codiConfigPaPianoFerie
	 */
	public String getCodiConfigPaPianoFerie() {
		return this.codiConfigPaPianoFerie;
	}

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

	/**
	 * @return the descConfigPaPianoFerie
	 */
	public String getDescConfigPaPianoFerie() {
		return this.descConfigPaPianoFerie;
	}

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

	/**
	 * @return the fkAmministrazionePk
	 */
	public Long getFkAmministrazionePk() {
		return this.fkAmministrazionePk;
	}

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

	/**
	 * @return the fkTipoOrganigramma
	 */
	public Long getFkTipoOrganigramma() {
		return this.fkTipoOrganigramma;
	}

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

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

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

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

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

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

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

	/**
	 * @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
	/**
	 * @return the DpercAutPianFerieH
	 */
	public Collection<DpercAutPianFerieH> getTheDpercAutPianFerieH() {
		return theDpercAutPianFerieH;
	}

	/**
	 * @param aDpercAutPianFerieHList to set
	 */
	public void setTheDpercAutPianFerieH(Collection<DpercAutPianFerieH> aDpercAutPianFerieHList) {
		theDpercAutPianFerieH = aDpercAutPianFerieHList;
	}

	/**
	 * @return the DconfigPaPfUoH
	 */
	public Collection<DconfigPaPfUoH> getTheDconfigPaPfUoH() {
		return theDconfigPaPfUoH;
	}

	/**
	 * @param aDconfigPaPfUoHList to set
	 */
	public void setTheDconfigPaPfUoH(Collection<DconfigPaPfUoH> aDconfigPaPfUoHList) {
		theDconfigPaPfUoH = aDconfigPaPfUoHList;
	}

	/// ADD CHILD
	public void addDpercAutPianFerieH(DpercAutPianFerieH dpercAutPianFerieH) {
		theDpercAutPianFerieH.add(dpercAutPianFerieH);
	}

	public void addDconfigPaPfUoH(DconfigPaPfUoH dconfigPaPfUoH) {
		theDconfigPaPfUoH.add(dconfigPaPfUoH);
	}

	// PARENT GETTER/SETTER

	// PARENT ID GETTER/SETTER

	// PARENT OBJECT TITLE

	// PARENT OBJECT KEY

	// 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(getSequIdConfigPaPianoFerie());
	}

	public String getObjectKeyById(Long identification) {
		if (identification == null) {
			return null;
		}
		StringBuilder output = new StringBuilder();
		output.append(identification);
		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;

		setSequIdConfigPaPianoFerie(getLongCheckedAgainstNullContent(array[ctr]));
	}

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

	// PREPERSIST

	@PrePersist
	public void prePersist() {
	}

	@PreUpdate
	public void PreUpdate() {
	}

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

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