package com.oguerreiro.resilient.domain;

import java.math.BigDecimal;

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;
import jakarta.validation.constraints.Pattern;

/**
 * Emission Factor
 */
@Entity
@Table(name = "emission_factor")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@ResilientSecurityResourceConfig()
public class EmissionFactor extends AbstractResilientLongIdEntity<EmissionFactor> {

  private static final long serialVersionUID = 1L;

  @NotNull
  @Column(name = "year", nullable = false)
  private Integer year;

  /**
   * Unique key, within the year
   */
  @NotNull
  @Pattern(regexp = "^[0-9]*$")
  @Column(name = "code", nullable = false)
  private String code;

  /**
   * The name or title for the Emission factor
   */
  @NotNull
  @Column(name = "name", nullable = false)
  private String name;

  /**
   * The unit of the Emission Factor.
   */
  @NotNull
  @Column(name = "unit", nullable = false)
  private String unit;

  /**
   * The value of the factor.
   */
  @NotNull
  @Column(name = "value", precision = 21, scale = 6, nullable = false)
  private BigDecimal value;

  /**
   * The source of the Emission Factor.
   */
  @Column(name = "source")
  private String source;

  /**
   * Comments
   */
  @Column(name = "comments")
  private String comments;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "variableCategories", "variables", "emissionFactors" }, allowSetters = true)
  private VariableScope variableScope;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "variables", "emissionFactors", "variableScope" }, allowSetters = true)
  private VariableCategory variableCategory;

  // jhipster-needle-entity-add-field - JHipster will add fields here

  public Integer getYear() {
    return this.year;
  }

  public EmissionFactor year(Integer year) {
    this.setYear(year);
    return this;
  }

  public void setYear(Integer year) {
    this.year = year;
  }

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

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

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

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

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

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

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

  public EmissionFactor unit(String unit) {
    this.setUnit(unit);
    return this;
  }

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

  public BigDecimal getValue() {
    return this.value;
  }

  public EmissionFactor value(BigDecimal value) {
    this.setValue(value);
    return this;
  }

  public void setValue(BigDecimal value) {
    this.value = value;
  }

  public String getSource() {
    return this.source;
  }

  public EmissionFactor source(String source) {
    this.setSource(source);
    return this;
  }

  public void setSource(String source) {
    this.source = source;
  }

  public String getComments() {
    return this.comments;
  }

  public EmissionFactor comments(String comments) {
    this.setComments(comments);
    return this;
  }

  public void setComments(String comments) {
    this.comments = comments;
  }

  public VariableScope getVariableScope() {
    return this.variableScope;
  }

  public void setVariableScope(VariableScope variableScope) {
    this.variableScope = variableScope;
  }

  public EmissionFactor variableScope(VariableScope variableScope) {
    this.setVariableScope(variableScope);
    return this;
  }

  public VariableCategory getVariableCategory() {
    return this.variableCategory;
  }

  public void setVariableCategory(VariableCategory variableCategory) {
    this.variableCategory = variableCategory;
  }

  public EmissionFactor variableCategory(VariableCategory variableCategory) {
    this.setVariableCategory(variableCategory);
    return this;
  }

//@formatter:off
  @Override
  public String toString() {
    return "EmissionFactor{" + 
              "id=" + getId() + 
              ", code='" + getCode() + "'" + 
              ", name='" + getName() + "'" + 
              ", unit='" + getUnit() + "'" + 
              ", value=" + getValue() + 
              ", source='" + getSource() + "'" + 
              ", comments='" + getComments() + "'" + 
              ", version=" + getVersion() + 
           "}";
  }
//@formatter:on
}
