package zeenea.connector.sqlserver.services.ssas.client.model.tabular;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link ConnectionDetails}.
 * <p>
 * Use the builder to create immutable instances:
 * {@code ImmutableConnectionDetails.builder()}.
 */
@Generated(from = "ConnectionDetails", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableConnectionDetails
    implements ConnectionDetails {
  private final Address address;

  private ImmutableConnectionDetails(Address address) {
    this.address = address;
  }

  /**
   * @return The value of the {@code address} attribute
   */
  @JsonProperty("address")
  @Override
  public Address getAddress() {
    return address;
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ConnectionDetails#getAddress() address} attribute.
   * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for address
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableConnectionDetails withAddress(Address value) {
    if (this.address == value) return this;
    Address newValue = Objects.requireNonNull(value, "address");
    return new ImmutableConnectionDetails(newValue);
  }

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

  private boolean equalTo(int synthetic, ImmutableConnectionDetails another) {
    return address.equals(another.address);
  }

  /**
   * Computes a hash code from attributes: {@code address}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + address.hashCode();
    return h;
  }

  /**
   * Prints the immutable value {@code ConnectionDetails} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "ConnectionDetails{"
        + "address=" + address
        + "}";
  }

  /**
   * Creates an immutable copy of a {@link ConnectionDetails} 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 ConnectionDetails instance
   */
  public static ImmutableConnectionDetails copyOf(ConnectionDetails instance) {
    if (instance instanceof ImmutableConnectionDetails) {
      return (ImmutableConnectionDetails) instance;
    }
    return ImmutableConnectionDetails.builder()
        .from(instance)
        .build();
  }

  /**
   * Creates a builder for {@link ImmutableConnectionDetails ImmutableConnectionDetails}.
   * <pre>
   * ImmutableConnectionDetails.builder()
   *    .address(zeenea.connector.sqlserver.services.ssas.client.model.tabular.Address) // required {@link ConnectionDetails#getAddress() address}
   *    .build();
   * </pre>
   * @return A new ImmutableConnectionDetails builder
   */
  public static ImmutableConnectionDetails.Builder builder() {
    return new ImmutableConnectionDetails.Builder();
  }

  /**
   * Builds instances of type {@link ImmutableConnectionDetails ImmutableConnectionDetails}.
   * 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 = "ConnectionDetails", generator = "Immutables")
  public static final class Builder {
    private static final long INIT_BIT_ADDRESS = 0x1L;
    private long initBits = 0x1L;

    private Address address;

    private Builder() {
    }

    /**
     * Fill a builder with attribute values from the provided {@code ConnectionDetails} 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(ConnectionDetails instance) {
      Objects.requireNonNull(instance, "instance");
      this.address(instance.getAddress());
      return this;
    }

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

    /**
     * Builds a new {@link ImmutableConnectionDetails ImmutableConnectionDetails}.
     * @return An immutable instance of ConnectionDetails
     * @throws java.lang.IllegalStateException if any required attributes are missing
     */
    public ImmutableConnectionDetails build() {
      if (initBits != 0) {
        throw new IllegalStateException(formatRequiredAttributesMessage());
      }
      return new ImmutableConnectionDetails(address);
    }

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