package com.oguerreiro.resilient.domain;

import java.time.Instant;

import com.oguerreiro.resilient.domain.enumeration.ResilientLogLevel;
import com.oguerreiro.resilient.security.custom.ResilientSecurityResourceConfig;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;

/**
 * Resilient Log
 * Generic persistent log messages, to use in several processes
 */
@Entity
@Table(name = "resilient_log")
@ResilientSecurityResourceConfig()
public class ResilientLog extends AbstractResilientLongIdEntity<ResilientLog> {

  private static final long serialVersionUID = 1L;

  @NotNull
  @Column(name = "owner_id", nullable = false)
  private Long ownerId;

  @NotNull
  @Column(name = "log_message", nullable = false)
  private String logMessage;

  /**
   * The creation date (insert). When the data was inserted into the system.
   */
  @NotNull
  @Column(name = "creation_date", nullable = false)
  private Instant creationDate;

  /**
   * The actual username logged into the system, that inserted the data. NOT a reference to the user, but the login
   * username.
   */
  @NotNull
  @Column(name = "creation_username", nullable = false)
  private String creationUsername;

  /**
   * Log Level
   */
  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "level", nullable = false)
  private ResilientLogLevel level;

  public String getLogMessage() {
    return this.logMessage;
  }

  public ResilientLog logMessage(String logMessage) {
    this.setLogMessage(logMessage);
    return this;
  }

  public void setLogMessage(String logMessage) {
    this.logMessage = logMessage;
  }

  public Instant getCreationDate() {
    return this.creationDate;
  }

  public ResilientLog creationDate(Instant creationDate) {
    this.setCreationDate(creationDate);
    return this;
  }

  public void setCreationDate(Instant creationDate) {
    this.creationDate = creationDate;
  }

  public String getCreationUsername() {
    return this.creationUsername;
  }

  public ResilientLog creationUsername(String creationUsername) {
    this.setCreationUsername(creationUsername);
    return this;
  }

  public void setCreationUsername(String creationUsername) {
    this.creationUsername = creationUsername;
  }

  public Long getOwnerId() {
    return this.ownerId;
  }

  public void setOwnerId(Long ownerId) {
    this.ownerId = ownerId;
  }

  public ResilientLog ownerId(Long ownerId) {
    this.setOwnerId(ownerId);
    return this;
  }

  public ResilientLogLevel getLevel() {
    return level;
  }

  public ResilientLog level(ResilientLogLevel level) {
    this.setLevel(level);
    return this;
  }

  public void setLevel(ResilientLogLevel level) {
    this.level = level;
  }

  //@formatter:off
  @Override
  public String toString() {
    return "ResilientLog{" + 
              "id=" + getId() +
              ", ownerId=" + getOwnerId() +
              ", level=" + getLevel() +
              ", logMessage='" + getLogMessage() + "'" + 
              ", creationDate='" + getCreationDate() + "'" + 
              ", creationUsername='" + getCreationUsername() + "'" + 
              ", version=" + getVersion() + 
           "}";
  }
//@formatter:on
}
