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;

/**
 * DashboardComponent
 * Defines a component for dashboard. Nothing more than a group of outputs (variables of output type)
 */
@Entity
@Table(name = "dashboard_component_detail")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@ResilientSecurityResourceConfig()
public class DashboardComponentDetail extends AbstractResilientLongIdEntity<DashboardComponentDetail> {
  private static final long serialVersionUID = 1L;

  @NotNull
  @Column(name = "name", nullable = false, unique = true)
  private String name;

  /**
   * The color to use for this detail (usually in charts)
   */
  @Column(name = "color")
  private String color;

  /**
   * Sets the order of the collection. When present, all collection queries should make an ORDER BY this column
   */
  @NotNull
  @Column(name = "idx_order", nullable = false)
  private Integer indexOrder;

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

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "dashboardComponentDetails", "dashboardComponentOrganizations" }, allowSetters = true)
  private DashboardComponent dashboardComponent;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "dashboardComponentDetails", "dashboardComponentOrganizations" }, allowSetters = true)
  private DashboardComponent targetDashboardComponent;

  @Column(name = "help", nullable = true)
  private String help;

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

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

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

  public String getHelp() {
    return this.help;
  }

  public DashboardComponentDetail help(String help) {
    this.setHelp(help);
    return this;
  }

  public void setHelp(String help) {
    this.help = help;
  }

  public String getColor() {
    return this.color;
  }

  public DashboardComponentDetail color(String color) {
    this.setColor(color);
    return this;
  }

  public void setColor(String color) {
    this.color = color;
  }

  public Integer getIndexOrder() {
    return this.indexOrder;
  }

  public DashboardComponentDetail indexOrder(Integer indexOrder) {
    this.setIndexOrder(indexOrder);
    return this;
  }

  public void setIndexOrder(Integer indexOrder) {
    this.indexOrder = indexOrder;
  }

  public DashboardComponent getDashboardComponent() {
    return this.dashboardComponent;
  }

  public void setDashboardComponent(DashboardComponent dashboardComponent) {
    this.dashboardComponent = dashboardComponent;
  }

  public DashboardComponentDetail dashboardComponent(DashboardComponent dashboardComponent) {
    this.setDashboardComponent(dashboardComponent);
    return this;
  }

  public DashboardComponent getTargetDashboardComponent() {
    return this.targetDashboardComponent;
  }

  public void setTargetDashboardComponent(DashboardComponent targetDashboardComponent) {
    this.targetDashboardComponent = targetDashboardComponent;
  }

  public DashboardComponentDetail targetDashboardComponent(DashboardComponent targetDashboardComponent) {
    this.setTargetDashboardComponent(targetDashboardComponent);
    return this;
  }

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

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

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

//@formatter:off
  @Override
  public String toString() {
    return "DashboardComponentDetail{" + 
            "id=" + getId() + 
            ", name='" + getName() + "'" +
            ", help='" + getHelp() + "'" +
            ", color='" + getColor() + "'" +
            ", indexOrder='" + getIndexOrder() + "'" +  
            ", version=" + getVersion() + 
          "}";
  }
//@formatter:on
}
