content: /*
   * SoulFire
   * Copyright (C) 2024  AlexProgrammerDE
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
   */
  package com.soulfiremc.server.database;
  
  import jakarta.persistence.*;
  import jakarta.validation.constraints.NotNull;
  import jakarta.validation.constraints.Size;
  import lombok.Getter;
  import lombok.Setter;
  import org.checkerframework.checker.nullness.qual.Nullable;
  import org.hibernate.annotations.CreationTimestamp;
  import org.hibernate.annotations.UpdateTimestamp;
  
  import java.time.Instant;
  import java.util.UUID;
  
  @Getter
  @Setter
  @Entity
  @Table(name = "instance_audit_logs")
  public final class InstanceAuditLogEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    private UUID id;
  
    @NotNull(message = "Audit log type cannot be null")
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private AuditLogType type;
  
    @Column
    @Nullable
    @Size(max = 4000, message = "Data must not exceed 4000 characters")
    private String data;
  
    @NotNull(message = "Instance cannot be null")
    @ManyToOne
    @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.CONSTRAINT))
    private InstanceEntity instance;
  
    @NotNull(message = "User cannot be null")
    @ManyToOne
    @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.CONSTRAINT))
    private UserEntity user;
  
    @CreationTimestamp
    @Column(nullable = false, updatable = false)
    private Instant createdAt;
  
    @UpdateTimestamp
    @Column(nullable = false)
    private Instant updatedAt;
  
    @Version
    private long version;
  
    public enum AuditLogType {
      EXECUTE_COMMAND,
      START_ATTACK,
      PAUSE_ATTACK,
      RESUME_ATTACK,
      STOP_ATTACK,
    }
  }
  