modeldb-main/backend/server/src/main/java/ai/verta/modeldb/versioning/autogenerated/_public/modeldb/versioning/model/AutogenQueryDatasetComponentBlob.java
// THIS FILE IS AUTO-GENERATED. DO NOT EDIT
package ai.verta.modeldb.versioning.autogenerated._public.modeldb.versioning.model;

import ai.verta.modeldb.common.exceptions.ModelDBException;
import ai.verta.modeldb.versioning.*;
import ai.verta.modeldb.versioning.blob.diff.*;
import ai.verta.modeldb.versioning.blob.diff.Function3;
import ai.verta.modeldb.versioning.blob.visitors.Visitor;
import com.pholser.junit.quickcheck.generator.*;
import com.pholser.junit.quickcheck.random.*;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.function.Function;
import org.apache.commons.codec.binary.Hex;

public class AutogenQueryDatasetComponentBlob implements ProtoType {
  private String DataSourceUri;
  private Long ExecutionTimestamp;
  private Long NumRecords;
  private String Query;

  public AutogenQueryDatasetComponentBlob() {
    this.DataSourceUri = "";
    this.ExecutionTimestamp = 0l;
    this.NumRecords = 0l;
    this.Query = "";
  }

  public Boolean isEmpty() {
    if (this.DataSourceUri != null && !this.DataSourceUri.equals("")) {
      return false;
    }
    if (this.ExecutionTimestamp != null && !this.ExecutionTimestamp.equals(0l)) {
      return false;
    }
    if (this.NumRecords != null && !this.NumRecords.equals(0l)) {
      return false;
    }
    if (this.Query != null && !this.Query.equals("")) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("{\"class\": \"AutogenQueryDatasetComponentBlob\", \"fields\": {");
    boolean first = true;
    if (this.DataSourceUri != null && !this.DataSourceUri.equals("")) {
      if (!first) sb.append(", ");
      sb.append("\"DataSourceUri\": " + "\"" + DataSourceUri + "\"");
      first = false;
    }
    if (this.ExecutionTimestamp != null && !this.ExecutionTimestamp.equals(0l)) {
      if (!first) sb.append(", ");
      sb.append("\"ExecutionTimestamp\": " + ExecutionTimestamp);
      first = false;
    }
    if (this.NumRecords != null && !this.NumRecords.equals(0l)) {
      if (!first) sb.append(", ");
      sb.append("\"NumRecords\": " + NumRecords);
      first = false;
    }
    if (this.Query != null && !this.Query.equals("")) {
      if (!first) sb.append(", ");
      sb.append("\"Query\": " + "\"" + Query + "\"");
      first = false;
    }
    sb.append("}}");
    return sb.toString();
  }

  // TODO: actually hash
  public String getSHA() throws NoSuchAlgorithmException {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    byte[] hash = digest.digest(this.toString().getBytes(StandardCharsets.UTF_8));
    return new String(new Hex().encode(hash));
  }

  @Override
  public int hashCode() {
    return Objects.hash(this.toString());
  }

  // TODO: not consider order on lists
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null) return false;
    if (!(o instanceof AutogenQueryDatasetComponentBlob)) return false;
    AutogenQueryDatasetComponentBlob other = (AutogenQueryDatasetComponentBlob) o;

    {
      Function3<String, String, Boolean> f = (x, y) -> x.equals(y);
      if (this.DataSourceUri != null || other.DataSourceUri != null) {
        if (this.DataSourceUri == null && other.DataSourceUri != null) return false;
        if (this.DataSourceUri != null && other.DataSourceUri == null) return false;
        if (!f.apply(this.DataSourceUri, other.DataSourceUri)) return false;
      }
    }
    {
      Function3<Long, Long, Boolean> f = (x, y) -> x.equals(y);
      if (this.ExecutionTimestamp != null || other.ExecutionTimestamp != null) {
        if (this.ExecutionTimestamp == null && other.ExecutionTimestamp != null) return false;
        if (this.ExecutionTimestamp != null && other.ExecutionTimestamp == null) return false;
        if (!f.apply(this.ExecutionTimestamp, other.ExecutionTimestamp)) return false;
      }
    }
    {
      Function3<Long, Long, Boolean> f = (x, y) -> x.equals(y);
      if (this.NumRecords != null || other.NumRecords != null) {
        if (this.NumRecords == null && other.NumRecords != null) return false;
        if (this.NumRecords != null && other.NumRecords == null) return false;
        if (!f.apply(this.NumRecords, other.NumRecords)) return false;
      }
    }
    {
      Function3<String, String, Boolean> f = (x, y) -> x.equals(y);
      if (this.Query != null || other.Query != null) {
        if (this.Query == null && other.Query != null) return false;
        if (this.Query != null && other.Query == null) return false;
        if (!f.apply(this.Query, other.Query)) return false;
      }
    }
    return true;
  }

  public AutogenQueryDatasetComponentBlob setDataSourceUri(String value) {
    this.DataSourceUri = Utils.removeEmpty(value);
    return this;
  }

  public String getDataSourceUri() {
    return this.DataSourceUri;
  }

  public AutogenQueryDatasetComponentBlob setExecutionTimestamp(Long value) {
    this.ExecutionTimestamp = Utils.removeEmpty(value);
    return this;
  }

  public Long getExecutionTimestamp() {
    return this.ExecutionTimestamp;
  }

  public AutogenQueryDatasetComponentBlob setNumRecords(Long value) {
    this.NumRecords = Utils.removeEmpty(value);
    return this;
  }

  public Long getNumRecords() {
    return this.NumRecords;
  }

  public AutogenQueryDatasetComponentBlob setQuery(String value) {
    this.Query = Utils.removeEmpty(value);
    return this;
  }

  public String getQuery() {
    return this.Query;
  }

  public static AutogenQueryDatasetComponentBlob fromProto(
      ai.verta.modeldb.versioning.QueryDatasetComponentBlob blob) {
    if (blob == null) {
      return null;
    }

    AutogenQueryDatasetComponentBlob obj = new AutogenQueryDatasetComponentBlob();
    {
      Function<ai.verta.modeldb.versioning.QueryDatasetComponentBlob, String> f =
          x -> (blob.getDataSourceUri());
      obj.setDataSourceUri(f.apply(blob));
    }
    {
      Function<ai.verta.modeldb.versioning.QueryDatasetComponentBlob, Long> f =
          x -> (blob.getExecutionTimestamp());
      obj.setExecutionTimestamp(f.apply(blob));
    }
    {
      Function<ai.verta.modeldb.versioning.QueryDatasetComponentBlob, Long> f =
          x -> (blob.getNumRecords());
      obj.setNumRecords(f.apply(blob));
    }
    {
      Function<ai.verta.modeldb.versioning.QueryDatasetComponentBlob, String> f =
          x -> (blob.getQuery());
      obj.setQuery(f.apply(blob));
    }
    return obj;
  }

  public ai.verta.modeldb.versioning.QueryDatasetComponentBlob.Builder toProto() {
    ai.verta.modeldb.versioning.QueryDatasetComponentBlob.Builder builder =
        ai.verta.modeldb.versioning.QueryDatasetComponentBlob.newBuilder();
    {
      if (this.DataSourceUri != null && !this.DataSourceUri.equals("")) {
        Function<ai.verta.modeldb.versioning.QueryDatasetComponentBlob.Builder, Void> f =
            x -> {
              builder.setDataSourceUri(this.DataSourceUri);
              return null;
            };
        f.apply(builder);
      }
    }
    {
      if (this.ExecutionTimestamp != null && !this.ExecutionTimestamp.equals(0l)) {
        Function<ai.verta.modeldb.versioning.QueryDatasetComponentBlob.Builder, Void> f =
            x -> {
              builder.setExecutionTimestamp(this.ExecutionTimestamp);
              return null;
            };
        f.apply(builder);
      }
    }
    {
      if (this.NumRecords != null && !this.NumRecords.equals(0l)) {
        Function<ai.verta.modeldb.versioning.QueryDatasetComponentBlob.Builder, Void> f =
            x -> {
              builder.setNumRecords(this.NumRecords);
              return null;
            };
        f.apply(builder);
      }
    }
    {
      if (this.Query != null && !this.Query.equals("")) {
        Function<ai.verta.modeldb.versioning.QueryDatasetComponentBlob.Builder, Void> f =
            x -> {
              builder.setQuery(this.Query);
              return null;
            };
        f.apply(builder);
      }
    }
    return builder;
  }

  public void preVisitShallow(Visitor visitor) throws ModelDBException {
    visitor.preVisitAutogenQueryDatasetComponentBlob(this);
  }

  public void preVisitDeep(Visitor visitor) throws ModelDBException {
    this.preVisitShallow(visitor);
    visitor.preVisitDeepString(this.DataSourceUri);
    visitor.preVisitDeepLong(this.ExecutionTimestamp);
    visitor.preVisitDeepLong(this.NumRecords);
    visitor.preVisitDeepString(this.Query);
  }

  public AutogenQueryDatasetComponentBlob postVisitShallow(Visitor visitor)
      throws ModelDBException {
    return visitor.postVisitAutogenQueryDatasetComponentBlob(this);
  }

  public AutogenQueryDatasetComponentBlob postVisitDeep(Visitor visitor) throws ModelDBException {
    this.setDataSourceUri(visitor.postVisitDeepString(this.DataSourceUri));
    this.setExecutionTimestamp(visitor.postVisitDeepLong(this.ExecutionTimestamp));
    this.setNumRecords(visitor.postVisitDeepLong(this.NumRecords));
    this.setQuery(visitor.postVisitDeepString(this.Query));
    return this.postVisitShallow(visitor);
  }
}
