package com.oguerreiro.resilient.domain;

import com.oguerreiro.resilient.security.custom.ResilientSecurityResourceConfig;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;

/**
 * Document with an attach
 */
@Entity
@Table(name = "document")
@ResilientSecurityResourceConfig()
public class Document extends AbstractResilientLongIdEntity<Document> {

  private static final long serialVersionUID = 1L;

  /**
   * A simple and small text with a title, for human reference and better relation
   */
  @NotNull
  @Column(name = "title", nullable = false)
  private String title;

  /**
   * An additional optional description
   */
  @Column(name = "description", nullable = true)
  private String description;

  /**
   * An Excel file, that must match a template for input
   */
  @Lob
  @Column(name = "data_file", nullable = false)
  private byte[] dataFile;

  @NotNull
  @Column(name = "data_file_content_type", nullable = false)
  private String dataFileContentType;

  public String getTitle() {
    return this.title;
  }

  public Document title(String title) {
    this.setTitle(title);
    return this;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getDescription() {
    return this.description;
  }

  public Document description(String description) {
    this.setDescription(description);
    return this;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public byte[] getDataFile() {
    return this.dataFile;
  }

  public Document dataFile(byte[] dataFile) {
    this.setDataFile(dataFile);
    return this;
  }

  public void setDataFile(byte[] dataFile) {
    this.dataFile = dataFile;
  }

  public String getDataFileContentType() {
    return this.dataFileContentType;
  }

  public Document dataFileContentType(String dataFileContentType) {
    this.dataFileContentType = dataFileContentType;
    return this;
  }

  public void setDataFileContentType(String dataFileContentType) {
    this.dataFileContentType = dataFileContentType;
  }

//@formatter:off
  @Override
  public String toString() {
    return "Document{" + 
              "id=" + getId() + 
              ", title='" + getTitle() + "'" +
              ", description='" + getDescription() + "'" + 
              ", dataFile='" + getDataFile() + "'" + 
              ", dataFileContentType='" + getDataFileContentType() + "'" + 
              ", version=" + getVersion() + 
           "}";
  }
//@formatter:on
}
