package com.faforever.api.data.domain;

import com.faforever.api.data.checks.IsReviewOwner;
import com.yahoo.elide.annotation.CreatePermission;
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.annotation.UpdatePermission;
import lombok.EqualsAndHashCode;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import java.sql.Timestamp;

@Setter
@Include(rootLevel = true, type = "review")
@EqualsAndHashCode(of = "id")
@Entity
@Table(name = "review")
@Inheritance(strategy = InheritanceType.JOINED)
@CreatePermission(expression = "Prefab.Role.All")
@DeletePermission(expression = IsReviewOwner.EXPRESSION)
public class Review {
  private Integer id;
  private String text;
  private Byte score;
  private Timestamp createTime;
  private Timestamp updateTime;
  private Player player;

  @Id
  @Column(name = "id")
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  public Integer getId() {
    return id;
  }

  @Column(name = "text")
  @UpdatePermission(expression = IsReviewOwner.EXPRESSION)
  public String getText() {
    return text;
  }

  @Column(name = "score")
  @DecimalMin("1")
  @DecimalMax("5")
  @UpdatePermission(expression = IsReviewOwner.EXPRESSION)
  public Byte getScore() {
    return score;
  }

  @Column(name = "create_time")
  public Timestamp getCreateTime() {
    return createTime;
  }

  @Column(name = "update_time")
  public Timestamp getUpdateTime() {
    return updateTime;
  }

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "user_id")
  @UpdatePermission(expression = "Prefab.Role.All and Prefab.Common.UpdateOnCreate")
  public Player getPlayer() {
    return player;
  }
}

@@ -446,119 +446,8 @@
 pe;%0A
-import javax.persistence.GeneratedValue;%0Aimport javax.persistence.GenerationType;%0Aimport javax.persistence.Id;%0A
 impo
@@ -726,35 +726,8 @@
 Min;
-%0Aimport java.sql.Timestamp;
 %0A%0A@S
@@ -1017,31 +1017,32 @@
 iew 
-%7B%0A  private Integer id;
+extends AbstractEntity %7B
 %0A  p
@@ -1097,216 +1097,22 @@
 ate 
-Timestamp createTime;%0A  private Timestamp updateTime;%0A  private Player player;%0A%0A  @Id%0A  @Column(name = %22id%22)%0A  @GeneratedValue(strategy = GenerationType.IDENTITY)%0A  public Integer getId() %7B%0A    return id;%0A  %7D
+Player player;
 %0A%0A  
@@ -1420,202 +1420,8 @@
  %7D%0A%0A
-  @Column(name = %22create_time%22)%0A  public Timestamp getCreateTime() %7B%0A    return createTime;%0A  %7D%0A%0A  @Column(name = %22update_time%22)%0A  public Timestamp getUpdateTime() %7B%0A    return updateTime;%0A  %7D%0A%0A
   @M

Make Review extend AbstractEntity