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;

/**
 * DashboardComponentOrganization
 * Defines a component restrition, to only some organizations. DashboardComponentDetail's are calculated the same way,
 * but filtered to only the allowed Organizations.
 */
@Entity
@Table(name = "dashboard_component_org")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@ResilientSecurityResourceConfig()
public class DashboardComponentOrganization extends AbstractResilientLongIdEntity<DashboardComponentOrganization> {
  private static final long serialVersionUID = 1L;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "children", "parent", "organizationtype" }, allowSetters = true)
  private Organization organization;

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

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

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

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

  public Organization getOrganization() {
    return this.organization;
  }

  public void setOrganization(Organization organization) {
    this.organization = organization;
  }

  public DashboardComponentOrganization organization(Organization organization) {
    this.setOrganization(organization);
    return this;
  }

//@formatter:off
  @Override
  public String toString() {
    return "DashboardComponentOrganization {" + 
            "id=" + getId() + 
            ", version=" + getVersion() + 
          "}";
  }
//@formatter:on
}
