package zeenea.connector.zdf.model;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * Immutable implementation of {@link ZdfField}.
 * <p>
 * Use the builder to create immutable instances:
 * {@code ImmutableZdfField.builder()}.
 */
@Generated(from = "ZdfField", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableZdfField implements ZdfField {
  @NotNull
  private final String name;
  private final @Nullable String description;
  private final @Nullable String nativeType;
  private final @Nullable String dataType;
  private final @Nullable Boolean nullable;
  private final @Nullable Boolean multivalued;
  private final @Nullable Boolean primaryKey;
  private final @Nullable String encoding;
  private final @Nullable String format;
  private final @Nullable String length;

  private ImmutableZdfField(
      String name,
      @Nullable String description,
      @Nullable String nativeType,
      @Nullable String dataType,
      @Nullable Boolean nullable,
      @Nullable Boolean multivalued,
      @Nullable Boolean primaryKey,
      @Nullable String encoding,
      @Nullable String format,
      @Nullable String length) {
    this.name = name;
    this.description = description;
    this.nativeType = nativeType;
    this.dataType = dataType;
    this.nullable = nullable;
    this.multivalued = multivalued;
    this.primaryKey = primaryKey;
    this.encoding = encoding;
    this.format = format;
    this.length = length;
  }

  /**
   * @return The value of the {@code name} attribute
   */
  @JsonProperty("name")
  @NotNull
  @Override
  public String name() {
    return name;
  }

  /**
   * @return The value of the {@code description} attribute
   */
  @JsonProperty("description")
  @Override
  public @Nullable String description() {
    return description;
  }

  /**
   * @return The value of the {@code nativeType} attribute
   */
  @JsonProperty("nativeType")
  @Override
  public @Nullable String nativeType() {
    return nativeType;
  }

  /**
   * @return The value of the {@code dataType} attribute
   */
  @JsonProperty("dataType")
  @Override
  public @Nullable String dataType() {
    return dataType;
  }

  /**
   * @return The value of the {@code nullable} attribute
   */
  @JsonProperty("nullable")
  @Override
  public @Nullable Boolean isNullable() {
    return nullable;
  }

  /**
   * @return The value of the {@code multivalued} attribute
   */
  @JsonProperty("multivalued")
  @Override
  public @Nullable Boolean isMultivalued() {
    return multivalued;
  }

  /**
   * @return The value of the {@code primaryKey} attribute
   */
  @JsonProperty("primaryKey")
  @Override
  public @Nullable Boolean isPrimaryKey() {
    return primaryKey;
  }

  /**
   * @return The value of the {@code encoding} attribute
   */
  @JsonProperty("encoding")
  @Override
  public @Nullable String encoding() {
    return encoding;
  }

  /**
   * @return The value of the {@code format} attribute
   */
  @JsonProperty("format")
  @Override
  public @Nullable String format() {
    return format;
  }

  /**
   * @return The value of the {@code length} attribute
   */
  @JsonProperty("length")
  @Override
  public @Nullable String length() {
    return length;
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#name() name} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for name
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withName(String value) {
    String newValue = Objects.requireNonNull(value, "name");
    if (this.name.equals(newValue)) return this;
    return new ImmutableZdfField(
        newValue,
        this.description,
        this.nativeType,
        this.dataType,
        this.nullable,
        this.multivalued,
        this.primaryKey,
        this.encoding,
        this.format,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#description() description} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for description (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withDescription(@Nullable String value) {
    if (Objects.equals(this.description, value)) return this;
    return new ImmutableZdfField(
        this.name,
        value,
        this.nativeType,
        this.dataType,
        this.nullable,
        this.multivalued,
        this.primaryKey,
        this.encoding,
        this.format,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#nativeType() nativeType} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for nativeType (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withNativeType(@Nullable String value) {
    if (Objects.equals(this.nativeType, value)) return this;
    return new ImmutableZdfField(
        this.name,
        this.description,
        value,
        this.dataType,
        this.nullable,
        this.multivalued,
        this.primaryKey,
        this.encoding,
        this.format,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#dataType() dataType} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for dataType (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withDataType(@Nullable String value) {
    if (Objects.equals(this.dataType, value)) return this;
    return new ImmutableZdfField(
        this.name,
        this.description,
        this.nativeType,
        value,
        this.nullable,
        this.multivalued,
        this.primaryKey,
        this.encoding,
        this.format,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#isNullable() nullable} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for nullable (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withNullable(@Nullable Boolean value) {
    if (Objects.equals(this.nullable, value)) return this;
    return new ImmutableZdfField(
        this.name,
        this.description,
        this.nativeType,
        this.dataType,
        value,
        this.multivalued,
        this.primaryKey,
        this.encoding,
        this.format,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#isMultivalued() multivalued} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for multivalued (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withMultivalued(@Nullable Boolean value) {
    if (Objects.equals(this.multivalued, value)) return this;
    return new ImmutableZdfField(
        this.name,
        this.description,
        this.nativeType,
        this.dataType,
        this.nullable,
        value,
        this.primaryKey,
        this.encoding,
        this.format,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#isPrimaryKey() primaryKey} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for primaryKey (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withPrimaryKey(@Nullable Boolean value) {
    if (Objects.equals(this.primaryKey, value)) return this;
    return new ImmutableZdfField(
        this.name,
        this.description,
        this.nativeType,
        this.dataType,
        this.nullable,
        this.multivalued,
        value,
        this.encoding,
        this.format,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#encoding() encoding} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for encoding (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withEncoding(@Nullable String value) {
    if (Objects.equals(this.encoding, value)) return this;
    return new ImmutableZdfField(
        this.name,
        this.description,
        this.nativeType,
        this.dataType,
        this.nullable,
        this.multivalued,
        this.primaryKey,
        value,
        this.format,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#format() format} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for format (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withFormat(@Nullable String value) {
    if (Objects.equals(this.format, value)) return this;
    return new ImmutableZdfField(
        this.name,
        this.description,
        this.nativeType,
        this.dataType,
        this.nullable,
        this.multivalued,
        this.primaryKey,
        this.encoding,
        value,
        this.length);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfField#length() length} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for length (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfField withLength(@Nullable String value) {
    if (Objects.equals(this.length, value)) return this;
    return new ImmutableZdfField(
        this.name,
        this.description,
        this.nativeType,
        this.dataType,
        this.nullable,
        this.multivalued,
        this.primaryKey,
        this.encoding,
        this.format,
        value);
  }

  /**
   * This instance is equal to all instances of {@code ImmutableZdfField} that have equal attribute values.
   * @return {@code true} if {@code this} is equal to {@code another} instance
   */
  @Override
  public boolean equals(@javax.annotation.Nullable Object another) {
    if (this == another) return true;
    return another instanceof ImmutableZdfField
        && equalTo(0, (ImmutableZdfField) another);
  }

  private boolean equalTo(int synthetic, ImmutableZdfField another) {
    return name.equals(another.name)
        && Objects.equals(description, another.description)
        && Objects.equals(nativeType, another.nativeType)
        && Objects.equals(dataType, another.dataType)
        && Objects.equals(nullable, another.nullable)
        && Objects.equals(multivalued, another.multivalued)
        && Objects.equals(primaryKey, another.primaryKey)
        && Objects.equals(encoding, another.encoding)
        && Objects.equals(format, another.format)
        && Objects.equals(length, another.length);
  }

  /**
   * Computes a hash code from attributes: {@code name}, {@code description}, {@code nativeType}, {@code dataType}, {@code nullable}, {@code multivalued}, {@code primaryKey}, {@code encoding}, {@code format}, {@code length}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + name.hashCode();
    h += (h << 5) + Objects.hashCode(description);
    h += (h << 5) + Objects.hashCode(nativeType);
    h += (h << 5) + Objects.hashCode(dataType);
    h += (h << 5) + Objects.hashCode(nullable);
    h += (h << 5) + Objects.hashCode(multivalued);
    h += (h << 5) + Objects.hashCode(primaryKey);
    h += (h << 5) + Objects.hashCode(encoding);
    h += (h << 5) + Objects.hashCode(format);
    h += (h << 5) + Objects.hashCode(length);
    return h;
  }

  /**
   * Prints the immutable value {@code ZdfField} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "ZdfField{"
        + "name=" + name
        + ", description=" + description
        + ", nativeType=" + nativeType
        + ", dataType=" + dataType
        + ", nullable=" + nullable
        + ", multivalued=" + multivalued
        + ", primaryKey=" + primaryKey
        + ", encoding=" + encoding
        + ", format=" + format
        + ", length=" + length
        + "}";
  }

  /**
   * Utility type used to correctly read immutable object from JSON representation.
   * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding infrastructure
   */
  @Generated(from = "ZdfField", generator = "Immutables")
  @Deprecated
  @JsonDeserialize
  @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
  static final class Json implements ZdfField {
    @javax.annotation.Nullable String name;
    @javax.annotation.Nullable String description;
    @javax.annotation.Nullable String nativeType;
    @javax.annotation.Nullable String dataType;
    @javax.annotation.Nullable Boolean nullable;
    @javax.annotation.Nullable Boolean multivalued;
    @javax.annotation.Nullable Boolean primaryKey;
    @javax.annotation.Nullable String encoding;
    @javax.annotation.Nullable String format;
    @javax.annotation.Nullable String length;
    @JsonProperty("name")
    public void setName(String name) {
      this.name = name;
    }
    @JsonProperty("description")
    public void setDescription(@Nullable String description) {
      this.description = description;
    }
    @JsonProperty("nativeType")
    public void setNativeType(@Nullable String nativeType) {
      this.nativeType = nativeType;
    }
    @JsonProperty("dataType")
    public void setDataType(@Nullable String dataType) {
      this.dataType = dataType;
    }
    @JsonProperty("nullable")
    public void setNullable(@Nullable Boolean nullable) {
      this.nullable = nullable;
    }
    @JsonProperty("multivalued")
    public void setMultivalued(@Nullable Boolean multivalued) {
      this.multivalued = multivalued;
    }
    @JsonProperty("primaryKey")
    public void setPrimaryKey(@Nullable Boolean primaryKey) {
      this.primaryKey = primaryKey;
    }
    @JsonProperty("encoding")
    public void setEncoding(@Nullable String encoding) {
      this.encoding = encoding;
    }
    @JsonProperty("format")
    public void setFormat(@Nullable String format) {
      this.format = format;
    }
    @JsonProperty("length")
    public void setLength(@Nullable String length) {
      this.length = length;
    }
    @Override
    public String name() { throw new UnsupportedOperationException(); }
    @Override
    public String description() { throw new UnsupportedOperationException(); }
    @Override
    public String nativeType() { throw new UnsupportedOperationException(); }
    @Override
    public String dataType() { throw new UnsupportedOperationException(); }
    @Override
    public Boolean isNullable() { throw new UnsupportedOperationException(); }
    @Override
    public Boolean isMultivalued() { throw new UnsupportedOperationException(); }
    @Override
    public Boolean isPrimaryKey() { throw new UnsupportedOperationException(); }
    @Override
    public String encoding() { throw new UnsupportedOperationException(); }
    @Override
    public String format() { throw new UnsupportedOperationException(); }
    @Override
    public String length() { throw new UnsupportedOperationException(); }
  }

  /**
   * @param json A JSON-bindable data structure
   * @return An immutable value type
   * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure
   */
  @Deprecated
  @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
  static ImmutableZdfField fromJson(Json json) {
    ImmutableZdfField.Builder builder = ImmutableZdfField.builder();
    if (json.name != null) {
      builder.name(json.name);
    }
    if (json.description != null) {
      builder.description(json.description);
    }
    if (json.nativeType != null) {
      builder.nativeType(json.nativeType);
    }
    if (json.dataType != null) {
      builder.dataType(json.dataType);
    }
    if (json.nullable != null) {
      builder.nullable(json.nullable);
    }
    if (json.multivalued != null) {
      builder.multivalued(json.multivalued);
    }
    if (json.primaryKey != null) {
      builder.primaryKey(json.primaryKey);
    }
    if (json.encoding != null) {
      builder.encoding(json.encoding);
    }
    if (json.format != null) {
      builder.format(json.format);
    }
    if (json.length != null) {
      builder.length(json.length);
    }
    return builder.build();
  }

  /**
   * Creates an immutable copy of a {@link ZdfField} value.
   * Uses accessors to get values to initialize the new immutable instance.
   * If an instance is already immutable, it is returned as is.
   * @param instance The instance to copy
   * @return A copied immutable ZdfField instance
   */
  public static ImmutableZdfField copyOf(ZdfField instance) {
    if (instance instanceof ImmutableZdfField) {
      return (ImmutableZdfField) instance;
    }
    return ImmutableZdfField.builder()
        .from(instance)
        .build();
  }

  /**
   * Creates a builder for {@link ImmutableZdfField ImmutableZdfField}.
   * <pre>
   * ImmutableZdfField.builder()
   *    .name(String) // required {@link ZdfField#name() name}
   *    .description(String | null) // nullable {@link ZdfField#description() description}
   *    .nativeType(String | null) // nullable {@link ZdfField#nativeType() nativeType}
   *    .dataType(String | null) // nullable {@link ZdfField#dataType() dataType}
   *    .nullable(Boolean | null) // nullable {@link ZdfField#isNullable() nullable}
   *    .multivalued(Boolean | null) // nullable {@link ZdfField#isMultivalued() multivalued}
   *    .primaryKey(Boolean | null) // nullable {@link ZdfField#isPrimaryKey() primaryKey}
   *    .encoding(String | null) // nullable {@link ZdfField#encoding() encoding}
   *    .format(String | null) // nullable {@link ZdfField#format() format}
   *    .length(String | null) // nullable {@link ZdfField#length() length}
   *    .build();
   * </pre>
   * @return A new ImmutableZdfField builder
   */
  public static ImmutableZdfField.Builder builder() {
    return new ImmutableZdfField.Builder();
  }

  /**
   * Builds instances of type {@link ImmutableZdfField ImmutableZdfField}.
   * Initialize attributes and then invoke the {@link #build()} method to create an
   * immutable instance.
   * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
   * but instead used immediately to create instances.</em>
   */
  @Generated(from = "ZdfField", generator = "Immutables")
  @NotThreadSafe
  public static final class Builder {
    private static final long INIT_BIT_NAME = 0x1L;
    private long initBits = 0x1L;

    private @javax.annotation.Nullable String name;
    private @javax.annotation.Nullable String description;
    private @javax.annotation.Nullable String nativeType;
    private @javax.annotation.Nullable String dataType;
    private @javax.annotation.Nullable Boolean nullable;
    private @javax.annotation.Nullable Boolean multivalued;
    private @javax.annotation.Nullable Boolean primaryKey;
    private @javax.annotation.Nullable String encoding;
    private @javax.annotation.Nullable String format;
    private @javax.annotation.Nullable String length;

    private Builder() {
    }

    /**
     * Fill a builder with attribute values from the provided {@code ZdfField} instance.
     * Regular attribute values will be replaced with those from the given instance.
     * Absent optional values will not replace present values.
     * @param instance The instance from which to copy values
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder from(ZdfField instance) {
      Objects.requireNonNull(instance, "instance");
      this.name(instance.name());
      @Nullable String descriptionValue = instance.description();
      if (descriptionValue != null) {
        description(descriptionValue);
      }
      @Nullable String nativeTypeValue = instance.nativeType();
      if (nativeTypeValue != null) {
        nativeType(nativeTypeValue);
      }
      @Nullable String dataTypeValue = instance.dataType();
      if (dataTypeValue != null) {
        dataType(dataTypeValue);
      }
      @Nullable Boolean nullableValue = instance.isNullable();
      if (nullableValue != null) {
        nullable(nullableValue);
      }
      @Nullable Boolean multivaluedValue = instance.isMultivalued();
      if (multivaluedValue != null) {
        multivalued(multivaluedValue);
      }
      @Nullable Boolean primaryKeyValue = instance.isPrimaryKey();
      if (primaryKeyValue != null) {
        primaryKey(primaryKeyValue);
      }
      @Nullable String encodingValue = instance.encoding();
      if (encodingValue != null) {
        encoding(encodingValue);
      }
      @Nullable String formatValue = instance.format();
      if (formatValue != null) {
        format(formatValue);
      }
      @Nullable String lengthValue = instance.length();
      if (lengthValue != null) {
        length(lengthValue);
      }
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#name() name} attribute.
     * @param name The value for name 
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("name")
    public final Builder name(String name) {
      this.name = Objects.requireNonNull(name, "name");
      initBits &= ~INIT_BIT_NAME;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#description() description} attribute.
     * @param description The value for description (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("description")
    public final Builder description(@Nullable String description) {
      this.description = description;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#nativeType() nativeType} attribute.
     * @param nativeType The value for nativeType (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("nativeType")
    public final Builder nativeType(@Nullable String nativeType) {
      this.nativeType = nativeType;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#dataType() dataType} attribute.
     * @param dataType The value for dataType (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("dataType")
    public final Builder dataType(@Nullable String dataType) {
      this.dataType = dataType;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#isNullable() nullable} attribute.
     * @param nullable The value for nullable (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("nullable")
    public final Builder nullable(@Nullable Boolean nullable) {
      this.nullable = nullable;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#isMultivalued() multivalued} attribute.
     * @param multivalued The value for multivalued (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("multivalued")
    public final Builder multivalued(@Nullable Boolean multivalued) {
      this.multivalued = multivalued;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#isPrimaryKey() primaryKey} attribute.
     * @param primaryKey The value for primaryKey (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("primaryKey")
    public final Builder primaryKey(@Nullable Boolean primaryKey) {
      this.primaryKey = primaryKey;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#encoding() encoding} attribute.
     * @param encoding The value for encoding (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("encoding")
    public final Builder encoding(@Nullable String encoding) {
      this.encoding = encoding;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#format() format} attribute.
     * @param format The value for format (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("format")
    public final Builder format(@Nullable String format) {
      this.format = format;
      return this;
    }

    /**
     * Initializes the value for the {@link ZdfField#length() length} attribute.
     * @param length The value for length (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("length")
    public final Builder length(@Nullable String length) {
      this.length = length;
      return this;
    }

    /**
     * Builds a new {@link ImmutableZdfField ImmutableZdfField}.
     * @return An immutable instance of ZdfField
     * @throws java.lang.IllegalStateException if any required attributes are missing
     */
    public ImmutableZdfField build() {
      if (initBits != 0) {
        throw new IllegalStateException(formatRequiredAttributesMessage());
      }
      return new ImmutableZdfField(
          name,
          description,
          nativeType,
          dataType,
          nullable,
          multivalued,
          primaryKey,
          encoding,
          format,
          length);
    }

    private String formatRequiredAttributesMessage() {
      List<String> attributes = new ArrayList<>();
      if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
      return "Cannot build ZdfField, some of required attributes are not set " + attributes;
    }
  }
}
