package dev.rheinsw.shared.entity;

import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

/**
 * Base Entity
 *
 * @author Thatsaphorn Atchariyaphap
 * @since 26.04.25
 */
@Getter
@Setter
@MappedSuperclass
public abstract class BaseEntity {

    @Column(name = "createdDateTime", nullable = false, updatable = false)
    private LocalDateTime createdDateTime;

    @Column(name = "modifiedDateTime")
    private LocalDateTime modifiedDateTime;

    @PrePersist
    protected void onCreate() {
        createdDateTime = LocalDateTime.now();
    }

    @PreUpdate
    protected void onUpdate() {
        modifiedDateTime = LocalDateTime.now();
    }
}