package org.jebot.models.jebot;

import lombok.Getter;
import lombok.Setter;
import org.jebot.util.SnowflakeId;

import javax.persistence.*;
import java.util.Date;


@Getter
@Setter
@MappedSuperclass
public class BotModel {
    @Id
    private Long id;

    @Column(updatable = false,name = "create_time")
    private Date createTime;

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

    @PrePersist
    public void prePersist() {
        if (this.id == null) {
            this.id = SnowflakeId.getId();
        }
        this.createTime = new Date();
        this.updateTime = new Date();
    }

    @PreUpdate
    public void preUpdate() {
        this.updateTime = new Date();
    }
}
