package com.remy.common.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.persistence.*;
import java.io.Serializable;
import java.time.OffsetDateTime;

@Data
@SuperBuilder
@NoArgsConstructor
@MappedSuperclass
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 1412134936159005266L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "create_time")
    private OffsetDateTime createTime;

    @Column(name = "update_time")
    private OffsetDateTime updateTime;

    @PrePersist
    public void prePersist() {
        this.setCreateTime(OffsetDateTime.now());
        this.setUpdateTime(OffsetDateTime.now());
    }

    @PreUpdate
    public void preUpdate() {
        this.setUpdateTime(OffsetDateTime.now());
    }

}
