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.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
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 ZdfProcess}.
 * <p>
 * Use the builder to create immutable instances:
 * {@code ImmutableZdfProcess.builder()}.
 */
@Generated(from = "ZdfProcess", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableZdfProcess implements ZdfProcess {
  private final @Nullable String path;
  @NotNull
  private final String name;
  private final @Nullable String description;
  private final @Nullable ZdfOwner owner;
  @NotNull
  private final List<ZdfDatasetRef> inputs;
  @NotNull
  private final List<ZdfDatasetRef> outputs;

  private ImmutableZdfProcess(
      @Nullable String path,
      String name,
      @Nullable String description,
      @Nullable ZdfOwner owner,
      List<ZdfDatasetRef> inputs,
      List<ZdfDatasetRef> outputs) {
    this.path = path;
    this.name = name;
    this.description = description;
    this.owner = owner;
    this.inputs = inputs;
    this.outputs = outputs;
  }

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

  /**
   * @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 owner} attribute
   */
  @JsonProperty("owner")
  @Override
  public @Nullable ZdfOwner owner() {
    return owner;
  }

  /**
   * @return The value of the {@code inputs} attribute
   */
  @JsonProperty("inputs")
  @NotNull
  @Override
  public List<ZdfDatasetRef> inputs() {
    return inputs;
  }

  /**
   * @return The value of the {@code outputs} attribute
   */
  @JsonProperty("outputs")
  @NotNull
  @Override
  public List<ZdfDatasetRef> outputs() {
    return outputs;
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfProcess#path() path} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for path (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfProcess withPath(@Nullable String value) {
    if (Objects.equals(this.path, value)) return this;
    return new ImmutableZdfProcess(value, this.name, this.description, this.owner, this.inputs, this.outputs);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfProcess#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 ImmutableZdfProcess withName(String value) {
    String newValue = Objects.requireNonNull(value, "name");
    if (this.name.equals(newValue)) return this;
    return new ImmutableZdfProcess(this.path, newValue, this.description, this.owner, this.inputs, this.outputs);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfProcess#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 ImmutableZdfProcess withDescription(@Nullable String value) {
    if (Objects.equals(this.description, value)) return this;
    return new ImmutableZdfProcess(this.path, this.name, value, this.owner, this.inputs, this.outputs);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link ZdfProcess#owner() owner} 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 owner (can be {@code null})
   * @return A modified copy of the {@code this} object
   */
  public final ImmutableZdfProcess withOwner(@Nullable ZdfOwner value) {
    if (this.owner == value) return this;
    return new ImmutableZdfProcess(this.path, this.name, this.description, value, this.inputs, this.outputs);
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link ZdfProcess#inputs() inputs}.
   * @param elements The elements to set
   * @return A modified copy of {@code this} object
   */
  public final ImmutableZdfProcess withInputs(ZdfDatasetRef... elements) {
    List<ZdfDatasetRef> newValue = List.of(elements);
    return new ImmutableZdfProcess(this.path, this.name, this.description, this.owner, newValue, this.outputs);
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link ZdfProcess#inputs() inputs}.
   * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
   * @param elements An iterable of inputs elements to set
   * @return A modified copy of {@code this} object
   */
  public final ImmutableZdfProcess withInputs(Iterable<? extends ZdfDatasetRef> elements) {
    if (this.inputs == elements) return this;
    List<ZdfDatasetRef> newValue = elements instanceof Collection<?>
        ? List.copyOf((Collection<? extends ZdfDatasetRef>) elements)
        : StreamSupport.stream(elements.spliterator(), false)
            .collect(Collectors.toUnmodifiableList());
    return new ImmutableZdfProcess(this.path, this.name, this.description, this.owner, newValue, this.outputs);
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link ZdfProcess#outputs() outputs}.
   * @param elements The elements to set
   * @return A modified copy of {@code this} object
   */
  public final ImmutableZdfProcess withOutputs(ZdfDatasetRef... elements) {
    List<ZdfDatasetRef> newValue = List.of(elements);
    return new ImmutableZdfProcess(this.path, this.name, this.description, this.owner, this.inputs, newValue);
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link ZdfProcess#outputs() outputs}.
   * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
   * @param elements An iterable of outputs elements to set
   * @return A modified copy of {@code this} object
   */
  public final ImmutableZdfProcess withOutputs(Iterable<? extends ZdfDatasetRef> elements) {
    if (this.outputs == elements) return this;
    List<ZdfDatasetRef> newValue = elements instanceof Collection<?>
        ? List.copyOf((Collection<? extends ZdfDatasetRef>) elements)
        : StreamSupport.stream(elements.spliterator(), false)
            .collect(Collectors.toUnmodifiableList());
    return new ImmutableZdfProcess(this.path, this.name, this.description, this.owner, this.inputs, newValue);
  }

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

  private boolean equalTo(int synthetic, ImmutableZdfProcess another) {
    return Objects.equals(path, another.path)
        && name.equals(another.name)
        && Objects.equals(description, another.description)
        && Objects.equals(owner, another.owner)
        && inputs.equals(another.inputs)
        && outputs.equals(another.outputs);
  }

  /**
   * Computes a hash code from attributes: {@code path}, {@code name}, {@code description}, {@code owner}, {@code inputs}, {@code outputs}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + Objects.hashCode(path);
    h += (h << 5) + name.hashCode();
    h += (h << 5) + Objects.hashCode(description);
    h += (h << 5) + Objects.hashCode(owner);
    h += (h << 5) + inputs.hashCode();
    h += (h << 5) + outputs.hashCode();
    return h;
  }

  /**
   * Prints the immutable value {@code ZdfProcess} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "ZdfProcess{"
        + "path=" + path
        + ", name=" + name
        + ", description=" + description
        + ", owner=" + owner
        + ", inputs=" + inputs
        + ", outputs=" + outputs
        + "}";
  }

  /**
   * 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 = "ZdfProcess", generator = "Immutables")
  @Deprecated
  @JsonDeserialize
  @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
  static final class Json implements ZdfProcess {
    @javax.annotation.Nullable String path;
    @javax.annotation.Nullable String name;
    @javax.annotation.Nullable String description;
    @javax.annotation.Nullable ZdfOwner owner;
    @javax.annotation.Nullable List<ZdfDatasetRef> inputs = List.of();
    @javax.annotation.Nullable List<ZdfDatasetRef> outputs = List.of();
    @JsonProperty("path")
    public void setPath(@Nullable String path) {
      this.path = path;
    }
    @JsonProperty("name")
    public void setName(String name) {
      this.name = name;
    }
    @JsonProperty("description")
    public void setDescription(@Nullable String description) {
      this.description = description;
    }
    @JsonProperty("owner")
    public void setOwner(@Nullable ZdfOwner owner) {
      this.owner = owner;
    }
    @JsonProperty("inputs")
    public void setInputs(List<ZdfDatasetRef> inputs) {
      this.inputs = inputs;
    }
    @JsonProperty("outputs")
    public void setOutputs(List<ZdfDatasetRef> outputs) {
      this.outputs = outputs;
    }
    @Override
    public String path() { throw new UnsupportedOperationException(); }
    @Override
    public String name() { throw new UnsupportedOperationException(); }
    @Override
    public String description() { throw new UnsupportedOperationException(); }
    @Override
    public ZdfOwner owner() { throw new UnsupportedOperationException(); }
    @Override
    public List<ZdfDatasetRef> inputs() { throw new UnsupportedOperationException(); }
    @Override
    public List<ZdfDatasetRef> outputs() { 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 ImmutableZdfProcess fromJson(Json json) {
    ImmutableZdfProcess.Builder builder = ImmutableZdfProcess.builder();
    if (json.path != null) {
      builder.path(json.path);
    }
    if (json.name != null) {
      builder.name(json.name);
    }
    if (json.description != null) {
      builder.description(json.description);
    }
    if (json.owner != null) {
      builder.owner(json.owner);
    }
    if (json.inputs != null) {
      builder.addAllInputs(json.inputs);
    }
    if (json.outputs != null) {
      builder.addAllOutputs(json.outputs);
    }
    return builder.build();
  }

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

  /**
   * Creates a builder for {@link ImmutableZdfProcess ImmutableZdfProcess}.
   * <pre>
   * ImmutableZdfProcess.builder()
   *    .path(String | null) // nullable {@link ZdfProcess#path() path}
   *    .name(String) // required {@link ZdfProcess#name() name}
   *    .description(String | null) // nullable {@link ZdfProcess#description() description}
   *    .owner(zeenea.connector.zdf.model.ZdfOwner | null) // nullable {@link ZdfProcess#owner() owner}
   *    .addInputs|addAllInputs(zeenea.connector.zdf.model.ZdfDatasetRef) // {@link ZdfProcess#inputs() inputs} elements
   *    .addOutputs|addAllOutputs(zeenea.connector.zdf.model.ZdfDatasetRef) // {@link ZdfProcess#outputs() outputs} elements
   *    .build();
   * </pre>
   * @return A new ImmutableZdfProcess builder
   */
  public static ImmutableZdfProcess.Builder builder() {
    return new ImmutableZdfProcess.Builder();
  }

  /**
   * Builds instances of type {@link ImmutableZdfProcess ImmutableZdfProcess}.
   * 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 = "ZdfProcess", 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 path;
    private @javax.annotation.Nullable String name;
    private @javax.annotation.Nullable String description;
    private @javax.annotation.Nullable ZdfOwner owner;
    private List<ZdfDatasetRef> inputs = new ArrayList<ZdfDatasetRef>();
    private List<ZdfDatasetRef> outputs = new ArrayList<ZdfDatasetRef>();

    private Builder() {
    }

    /**
     * Fill a builder with attribute values from the provided {@code zeenea.connector.zdf.model.ZdfItem} instance.
     * @param instance The instance from which to copy values
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder from(ZdfItem instance) {
      Objects.requireNonNull(instance, "instance");
      from((short) 0, (Object) instance);
      return this;
    }

    /**
     * Fill a builder with attribute values from the provided {@code zeenea.connector.zdf.model.ZdfProcess} instance.
     * @param instance The instance from which to copy values
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder from(ZdfProcess instance) {
      Objects.requireNonNull(instance, "instance");
      from((short) 0, (Object) instance);
      return this;
    }

    private void from(short _unused, Object object) {
      long bits = 0;
      if (object instanceof ZdfItem) {
        ZdfItem instance = (ZdfItem) object;
        if ((bits & 0x1L) == 0) {
          @Nullable ZdfOwner ownerValue = instance.owner();
          if (ownerValue != null) {
            owner(ownerValue);
          }
          bits |= 0x1L;
        }
        if ((bits & 0x8L) == 0) {
          this.name(instance.name());
          bits |= 0x8L;
        }
        if ((bits & 0x2L) == 0) {
          @Nullable String descriptionValue = instance.description();
          if (descriptionValue != null) {
            description(descriptionValue);
          }
          bits |= 0x2L;
        }
        if ((bits & 0x4L) == 0) {
          @Nullable String pathValue = instance.path();
          if (pathValue != null) {
            path(pathValue);
          }
          bits |= 0x4L;
        }
      }
      if (object instanceof ZdfProcess) {
        ZdfProcess instance = (ZdfProcess) object;
        if ((bits & 0x1L) == 0) {
          @Nullable ZdfOwner ownerValue = instance.owner();
          if (ownerValue != null) {
            owner(ownerValue);
          }
          bits |= 0x1L;
        }
        addAllOutputs(instance.outputs());
        if ((bits & 0x8L) == 0) {
          this.name(instance.name());
          bits |= 0x8L;
        }
        if ((bits & 0x2L) == 0) {
          @Nullable String descriptionValue = instance.description();
          if (descriptionValue != null) {
            description(descriptionValue);
          }
          bits |= 0x2L;
        }
        if ((bits & 0x4L) == 0) {
          @Nullable String pathValue = instance.path();
          if (pathValue != null) {
            path(pathValue);
          }
          bits |= 0x4L;
        }
        addAllInputs(instance.inputs());
      }
    }

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

    /**
     * Initializes the value for the {@link ZdfProcess#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 ZdfProcess#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 ZdfProcess#owner() owner} attribute.
     * @param owner The value for owner (can be {@code null})
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("owner")
    public final Builder owner(@Nullable ZdfOwner owner) {
      this.owner = owner;
      return this;
    }

    /**
     * Adds one element to {@link ZdfProcess#inputs() inputs} list.
     * @param element A inputs element
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder addInputs(ZdfDatasetRef element) {
      this.inputs.add(Objects.requireNonNull(element, "inputs element"));
      return this;
    }

    /**
     * Adds elements to {@link ZdfProcess#inputs() inputs} list.
     * @param elements An array of inputs elements
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder addInputs(ZdfDatasetRef... elements) {
      for (ZdfDatasetRef element : elements) {
        this.inputs.add(Objects.requireNonNull(element, "inputs element"));
      }
      return this;
    }


    /**
     * Sets or replaces all elements for {@link ZdfProcess#inputs() inputs} list.
     * @param elements An iterable of inputs elements
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("inputs")
    public final Builder inputs(Iterable<? extends ZdfDatasetRef> elements) {
      this.inputs.clear();
      return addAllInputs(elements);
    }

    /**
     * Adds elements to {@link ZdfProcess#inputs() inputs} list.
     * @param elements An iterable of inputs elements
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder addAllInputs(Iterable<? extends ZdfDatasetRef> elements) {
      for (ZdfDatasetRef element : elements) {
        this.inputs.add(Objects.requireNonNull(element, "inputs element"));
      }
      return this;
    }

    /**
     * Adds one element to {@link ZdfProcess#outputs() outputs} list.
     * @param element A outputs element
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder addOutputs(ZdfDatasetRef element) {
      this.outputs.add(Objects.requireNonNull(element, "outputs element"));
      return this;
    }

    /**
     * Adds elements to {@link ZdfProcess#outputs() outputs} list.
     * @param elements An array of outputs elements
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder addOutputs(ZdfDatasetRef... elements) {
      for (ZdfDatasetRef element : elements) {
        this.outputs.add(Objects.requireNonNull(element, "outputs element"));
      }
      return this;
    }


    /**
     * Sets or replaces all elements for {@link ZdfProcess#outputs() outputs} list.
     * @param elements An iterable of outputs elements
     * @return {@code this} builder for use in a chained invocation
     */
    @JsonProperty("outputs")
    public final Builder outputs(Iterable<? extends ZdfDatasetRef> elements) {
      this.outputs.clear();
      return addAllOutputs(elements);
    }

    /**
     * Adds elements to {@link ZdfProcess#outputs() outputs} list.
     * @param elements An iterable of outputs elements
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder addAllOutputs(Iterable<? extends ZdfDatasetRef> elements) {
      for (ZdfDatasetRef element : elements) {
        this.outputs.add(Objects.requireNonNull(element, "outputs element"));
      }
      return this;
    }

    /**
     * Builds a new {@link ImmutableZdfProcess ImmutableZdfProcess}.
     * @return An immutable instance of ZdfProcess
     * @throws java.lang.IllegalStateException if any required attributes are missing
     */
    public ImmutableZdfProcess build() {
      if (initBits != 0) {
        throw new IllegalStateException(formatRequiredAttributesMessage());
      }
      return new ImmutableZdfProcess(path, name, description, owner, List.copyOf(inputs), List.copyOf(outputs));
    }

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