package com.oguerreiro.resilient.domain;

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

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

/**
 * Metadata Value
 * The value of a metadata property.
 */
@Entity
@Table(name = "metadata_value")
@ResilientSecurityResourceConfig()
public class MetadataValue extends AbstractResilientLongIdEntity<MetadataValue> {

  private static final long serialVersionUID = 1L;

  /**
   * Functional relational key to MetadataProperty
   */
  @NotNull
  @Column(name = "metadata_property_code", nullable = false)
  private String metadataPropertyCode;

  /**
   * The target domain key that this MetadataValue belongs. Its a class name or a key provided by the consumer. <br>
   * Used with targetDomainId to create as unique relation with the target domain
   * 
   * @see targetDomainId
   */
  @NotNull
  @Column(name = "target_domain_key", nullable = false)
  private String targetDomainKey;

  /**
   * The target domain Id that this MetadataValue belongs. <br>
   * Used with targetDomainKey to create as unique relation with the target domain
   * 
   * @see targetDomainKey
   */
  @NotNull
  @Column(name = "target_domain_id", nullable = false)
  private Long targetDomainId;

  /**
   * The value of the MetadataProperty, persisted as a string. <br>
   */
  @Column(name = "value")
  private String value;

  public String getMetadataPropertyCode() {
    return this.metadataPropertyCode;
  }

  public MetadataValue metadataPropertyCode(String metadataPropertyCode) {
    this.setMetadataPropertyCode(metadataPropertyCode);
    return this;
  }

  public void setMetadataPropertyCode(String metadataPropertyCode) {
    this.metadataPropertyCode = metadataPropertyCode;
  }

  public String getTargetDomainKey() {
    return this.targetDomainKey;
  }

  public MetadataValue targetDomainKey(String targetDomainKey) {
    this.setTargetDomainKey(targetDomainKey);
    return this;
  }

  public void setTargetDomainKey(String targetDomainKey) {
    this.targetDomainKey = targetDomainKey;
  }

  public Long getTargetDomainId() {
    return this.targetDomainId;
  }

  public MetadataValue targetDomainId(Long targetDomainId) {
    this.setTargetDomainId(targetDomainId);
    return this;
  }

  public void setTargetDomainId(Long targetDomainId) {
    this.targetDomainId = targetDomainId;
  }

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

  public MetadataValue value(String value) {
    this.setValue(value);
    return this;
  }

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

//@formatter:off
  @Override
  public String toString() {
    return "MetadataValue{" +
              "id=" + getId() +
              ", metadataPropertyCode='" + getMetadataPropertyCode() + "'" +
              ", targetDomainKey='" + getTargetDomainKey() + "'" +
              ", targetDomainId=" + getTargetDomainId() +
              ", value='" + getValue() + "'" +
              ", version=" + getVersion() +
           "}";
  }
//@formatter:on
}
