package com.oguerreiro.resilient.domain;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

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;

/**
 * Variable Class
 * A sub-variable classification. Example: Variable=FUEL CONSUMPTIOM; CLASS=GASOLINE; OR ELECTRICAL; ETC...
 */
@Entity
@Table(name = "variable_class")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@ResilientSecurityResourceConfig()
public class VariableClass extends AbstractResilientLongIdEntity<VariableClass> {

  private static final long serialVersionUID = 1L;

  /**
   * Code of the class. Must be unique within the Variavle
   */
  @NotNull
  @Column(name = "code", nullable = false)
  private String code;

  /**
   * Human name of the class. Must be unique within the Variable, because it will be used as key for the Excel
   * integration data.
   */
  @NotNull
  @Column(name = "name", nullable = false)
  private String name;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "variableClasses" }, allowSetters = true)
  private VariableClassType variableClassType;

  public String getCode() {
    return this.code;
  }

  public VariableClass code(String code) {
    this.setCode(code);
    return this;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getName() {
    return this.name;
  }

  public VariableClass name(String name) {
    this.setName(name);
    return this;
  }

  public void setName(String name) {
    this.name = name;
  }

  public VariableClassType getVariableClassType() {
    return this.variableClassType;
  }

  public void setVariableClassType(VariableClassType variableClassType) {
    this.variableClassType = variableClassType;
  }

  public VariableClass variableClassType(VariableClassType variableClassType) {
    this.setVariableClassType(variableClassType);
    return this;
  }

//@formatter:off
  @Override
  public String toString() {
    return "VariableClass{" +
              "id=" + getId() +
              ", code='" + getCode() + "'" +
              ", name='" + getName() + "'" +
              ", version=" + getVersion() +
           "}";
  }
//@formatter:on
}
