package com.oguerreiro.resilient.domain;

import java.time.Instant;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.oguerreiro.resilient.security.custom.ResilientSecurityResourceConfig;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;

/**
 * Input data upload file
 * Users can upload an Excel file with InputData that will automatically insert values in the table InputData
 */
@Entity
@Table(name = "input_data_upload_log")
@ResilientSecurityResourceConfig()
public class InputDataUploadLog extends AbstractResilientLongIdEntity<InputDataUploadLog> {

  private static final long serialVersionUID = 1L;

  /**
   * The log of the event. Eg. \"InputDataUpload created\"; \"InputDataUpload replaced with new file\"; \"125 records
   * inserted\"; \"User XPTO confirmed the file replacement.\"
   */
  @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;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "inputData", "inputDataUploadLogs", "period", "periodVersion",
      "owner" }, allowSetters = true)
  private InputDataUpload inputDataUpload;

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

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

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

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

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

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

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

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

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

  public InputDataUpload getInputDataUpload() {
    return this.inputDataUpload;
  }

  public void setInputDataUpload(InputDataUpload inputDataUpload) {
    this.inputDataUpload = inputDataUpload;
  }

  public InputDataUploadLog inputDataUpload(InputDataUpload inputDataUpload) {
    this.setInputDataUpload(inputDataUpload);
    return this;
  }

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