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.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

/**
 * Variable allowed input units. Also defines the converters needed if the
 */
@Entity
@Table(name = "variable_units")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@ResilientSecurityResourceConfig()
public class VariableUnits extends AbstractResilientLongIdEntity<VariableUnits> {

  private static final long serialVersionUID = 1L;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "variableUnits", "baseUnit", "variableScope",
      "variableCategory" }, allowSetters = true)
  private Variable variable;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "unitType" }, allowSetters = true)
  private Unit unit;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "unitType", "fromUnit", "toUnit" }, allowSetters = true)
  private UnitConverter unitConverter;

  public Variable getVariable() {
    return this.variable;
  }

  public void setVariable(Variable variable) {
    this.variable = variable;
  }

  public VariableUnits variable(Variable variable) {
    this.setVariable(variable);
    return this;
  }

  public Unit getUnit() {
    return this.unit;
  }

  public void setUnit(Unit unit) {
    this.unit = unit;
  }

  public VariableUnits unit(Unit unit) {
    this.setUnit(unit);
    return this;
  }

  public UnitConverter getUnitConverter() {
    return this.unitConverter;
  }

  public void setUnitConverter(UnitConverter unitConverter) {
    this.unitConverter = unitConverter;
  }

  public VariableUnits unitConverter(UnitConverter unitConverter) {
    this.setUnitConverter(unitConverter);
    return this;
  }

  // prettier-ignore
  @Override
  public String toString() {
    return "VariableUnits{" + "id=" + getId() + ", version=" + getVersion() + "}";
  }
}
