package gaf3.core.jpa

import java.time.LocalDateTime
import javax.persistence.Column
import javax.persistence.MappedSuperclass
import javax.persistence.PrePersist
import javax.persistence.PreUpdate

@MappedSuperclass
abstract class GafTimestamp {
    @PrePersist
    open fun insertTime() {
        createdAt = createdAt ?: LocalDateTime.now()
        updatedAt = updatedAt ?: createdAt
    }

    @PreUpdate
    open fun updateTime() {
        updatedAt = LocalDateTime.now()
    }

    @Column(name = "CREATED_AT")
    open var createdAt: LocalDateTime? = null

    @Column(name = "UPDATED_AT")
    open var updatedAt: LocalDateTime? = null

}