package marketing.heyday.hartmann.fotodocumentation.core.model;

import java.util.Date;

import jakarta.persistence.*;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 
 * 
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: heyday Marketing GmbH</p>
 * @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
 * @version 1.0
 * 
 * created: 19 Jan 2026
 */
@MappedSuperclass
public abstract class AbstractDateEntity extends AbstractEntity {
	private static final long serialVersionUID = 1L;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "JPA_CREATED", nullable = false)
	@JsonIgnore
	private Date jpaCreated;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "JPA_UPDATED", nullable = false)
	@JsonIgnore
	private Date jpaUpdated;

	@Column(name = "JPA_ACTIVE", nullable = false)
	private boolean active = true;

	@Version
	@Column(name = "JPA_VERSION", nullable = false)
	private int jpaVersion = 0;

	@PrePersist
	protected void onCreate() {
		Date now = new Date();
		jpaCreated = now;
		jpaUpdated = now;
	}

	@PreUpdate
	protected void onUpdate() {
		jpaUpdated = new Date();
	}

	public Date getJpaCreated() {
		return jpaCreated;
	}

	public Date getJpaUpdated() {
		return jpaUpdated;
	}

	public int getJpaVersion() {
		return jpaVersion;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
}
