package com.oguerreiro.resilient.domain;

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

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

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

/**
 * Dashboard
 * Defines a dashboard for presenting DashboardComponents.
 */
@Entity
@Table(name = "dashboard")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@ResilientSecurityResourceConfig()
public class Dashboard extends AbstractResilientLongIdEntity<Dashboard> {

  private static final long serialVersionUID = 1L;

  public static final String DASHBOARD_EMISSIONS_CODE = "EMISSIONS";
  public static final String DASHBOARD_INDICATORS_CODE = "INDICATORS";

  /**
   * User defined code. Must be unique
   * There's 2 internal codes:
   * - EMISSIONS
   * - INDICATORS
   */
  @NotNull
  @Size(min = 1)
  @Column(name = "code", nullable = false, unique = true)
  private String code;

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

  @Column(name = "description")
  private String description;

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

  /**
   * When set to true, means this is a specific dashboard to use in the app. It CAN'T be deleted.
   */
  @Column(name = "is_internal")
  private Boolean isInternal;

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

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

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

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

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

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

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

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

  public Boolean getIsInternal() {
    return this.isInternal;
  }

  public Dashboard isInternal(Boolean isInternal) {
    this.setIsInternal(isInternal);
    return this;
  }

  public void setIsInternal(Boolean isInternal) {
    this.isInternal = isInternal;
  }

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