package com.pingcap.community.blogserver.entity;

import com.fasterxml.jackson.annotation.JsonView;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.util.Date;

@MappedSuperclass
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {

  public interface TimeInfoView {}

  @CreatedBy
  @Column(name = "creator_id", updatable = false, nullable = false)
  private Long creatorId;

  @JsonView(TimeInfoView.class)
  @CreatedDate
  @Column(name = "created_at", updatable = false, columnDefinition = "datetime not null default CURRENT_TIMESTAMP")
  private Date createdAt;

  @LastModifiedBy
  @Column(name = "modifier_id", nullable = false)
  private Long modifierId;

  @JsonView(TimeInfoView.class)
  @LastModifiedDate
  @Column(name = "last_modified_at", columnDefinition = "datetime not null default CURRENT_TIMESTAMP")
  private Date lastModifiedAt;

  @JsonView(TimeInfoView.class)
  @Column(name = "deleted_at", insertable = false)
  private Date deletedAt;

}
