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 ZdfOwner}.
 * <p>
 * Use the builder to create immutable instances:
 * {@code ImmutableZdfOwner.builder()}.
 */
@Generated(from = "ZdfOwner", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableZdfOwner implements ZdfOwner {
  @NotNull
  private final String role;
  @NotNull
  private final String email;
  private final @Nullable String firstname;
  private final @Nullable String lastname;

  private ImmutableZdfOwner(
      String role,
      String email,
      @Nullable String firstname,
      @Nullable String lastname) {
    this.role = role;
    this.email = email;
    this.firstname = firstname;
    this.lastname = lastname;
  }

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

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

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

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

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfOwner#role() role} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for role
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfOwner withRole(String value) {
    String newValue = Objects.requireNonNull(value, "role");
    if (this.role.equals(newValue)) return this;
    return new ImmutableZdfOwner(newValue, this.email, this.firstname, this.lastname);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfOwner#email() email} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for email
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfOwner withEmail(String value) {
    String newValue = Objects.requireNonNull(value, "email");
    if (this.email.equals(newValue)) return this;
    return new ImmutableZdfOwner(this.role, newValue, this.firstname, this.lastname);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfOwner#firstname() firstname} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for firstname (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfOwner withFirstname(@Nullable String value) {
    if (Objects.equals(this.firstname, value)) return this;
    return new ImmutableZdfOwner(this.role, this.email, value, this.lastname);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfOwner#lastname() lastname} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for lastname (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfOwner withLastname(@Nullable String value) {
    if (Objects.equals(this.lastname, value)) return this;
    return new ImmutableZdfOwner(this.role, this.email, this.firstname, value);
  }

  /**
   * This instance is equal to all instances of {@code ImmutableZdfOwner} 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 ImmutableZdfOwner
        && equalTo(0, (ImmutableZdfOwner) another);
  }

  private boolean equalTo(int synthetic, ImmutableZdfOwner another) {
    return role.equals(another.role)
        && email.equals(another.email)
        && Objects.equals(firstname, another.firstname)
        && Objects.equals(lastname, another.lastname);
  }

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

  /**
   * Prints the immutable value {@code ZdfOwner} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "ZdfOwner{"
        + "role=" + role
        + ", email=" + email
        + ", firstname=" + firstname
        + ", lastname=" + lastname
        + "}";
  }

  /**
   * 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 = "ZdfOwner", generator = "Immutables")
  @Deprecated
  @JsonDeserialize
  @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
  static final class Json implements ZdfOwner {
    @javax.annotation.Nullable String role;
    @javax.annotation.Nullable String email;
    @javax.annotation.Nullable String firstname;
    @javax.annotation.Nullable String lastname;
    @JsonProperty("role")
    public void setRole(String role) {
      this.role = role;
    }
    @JsonProperty("email")
    public void setEmail(String email) {
      this.email = email;
    }
    @JsonProperty("firstname")
    public void setFirstname(@Nullable String firstname) {
      this.firstname = firstname;
    }
    @JsonProperty("lastname")
    public void setLastname(@Nullable String lastname) {
      this.lastname = lastname;
    }
    @Override
    public String role() { throw new UnsupportedOperationException(); }
    @Override
    public String email() { throw new UnsupportedOperationException(); }
    @Override
    public String firstname() { throw new UnsupportedOperationException(); }
    @Override
    public String lastname() { 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 ImmutableZdfOwner fromJson(Json json) {
    ImmutableZdfOwner.Builder builder = ImmutableZdfOwner.builder();
    if (json.role != null) {
      builder.role(json.role);
    }
    if (json.email != null) {
      builder.email(json.email);
    }
    if (json.firstname != null) {
      builder.firstname(json.firstname);
    }
    if (json.lastname != null) {
      builder.lastname(json.lastname);
    }
    return builder.build();
  }

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

  /**
   * Creates a builder for {@link ImmutableZdfOwner ImmutableZdfOwner}.
   * <pre>
   * ImmutableZdfOwner.builder()
   *    .role(String) // required {@link ZdfOwner#role() role}
   *    .email(String) // required {@link ZdfOwner#email() email}
   *    .firstname(String | null) // nullable {@link ZdfOwner#firstname() firstname}
   *    .lastname(String | null) // nullable {@link ZdfOwner#lastname() lastname}
   *    .build();
   * </pre>
   * @return A new ImmutableZdfOwner builder
   */
  public static ImmutableZdfOwner.Builder builder() {
    return new ImmutableZdfOwner.Builder();
  }

  /**
   * Builds instances of type {@link ImmutableZdfOwner ImmutableZdfOwner}.
   * 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 = "ZdfOwner", generator = "Immutables")
  @NotThreadSafe
  public static final class Builder {
    private static final long INIT_BIT_ROLE = 0x1L;
    private static final long INIT_BIT_EMAIL = 0x2L;
    private long initBits = 0x3L;

    private @javax.annotation.Nullable String role;
    private @javax.annotation.Nullable String email;
    private @javax.annotation.Nullable String firstname;
    private @javax.annotation.Nullable String lastname;

    private Builder() {
    }

    /**
     * Fill a builder with attribute values from the provided {@code ZdfOwner} 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(ZdfOwner instance) {
      Objects.requireNonNull(instance, "instance");
      this.role(instance.role());
      this.email(instance.email());
      @Nullable String firstnameValue = instance.firstname();
      if (firstnameValue != null) {
        firstname(firstnameValue);
      }
      @Nullable String lastnameValue = instance.lastname();
      if (lastnameValue != null) {
        lastname(lastnameValue);
      }
      return this;
    }

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

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

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

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

    /**
     * Builds a new {@link ImmutableZdfOwner ImmutableZdfOwner}.
     * @return An immutable instance of ZdfOwner
     * @throws java.lang.IllegalStateException if any required attributes are missing
     */
    public ImmutableZdfOwner build() {
      if (initBits != 0) {
        throw new IllegalStateException(formatRequiredAttributesMessage());
      }
      return new ImmutableZdfOwner(role, email, firstname, lastname);
    }

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