// 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 AutogenNotebookCodeDiff implements ProtoType {
  private AutogenGitCodeDiff GitRepo;
  private AutogenPathDatasetComponentDiff Path;

  public AutogenNotebookCodeDiff() {
    this.GitRepo = null;
    this.Path = null;
  }

  public Boolean isEmpty() {
    if (this.GitRepo != null && !this.GitRepo.equals(null)) {
      return false;
    }
    if (this.Path != null && !this.Path.equals(null)) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("{\"class\": \"AutogenNotebookCodeDiff\", \"fields\": {");
    boolean first = true;
    if (this.GitRepo != null && !this.GitRepo.equals(null)) {
      if (!first) sb.append(", ");
      sb.append("\"GitRepo\": " + GitRepo);
      first = false;
    }
    if (this.Path != null && !this.Path.equals(null)) {
      if (!first) sb.append(", ");
      sb.append("\"Path\": " + Path);
      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 AutogenNotebookCodeDiff)) return false;
    AutogenNotebookCodeDiff other = (AutogenNotebookCodeDiff) o;

    {
      Function3<AutogenGitCodeDiff, AutogenGitCodeDiff, Boolean> f = (x, y) -> x.equals(y);
      if (this.GitRepo != null || other.GitRepo != null) {
        if (this.GitRepo == null && other.GitRepo != null) return false;
        if (this.GitRepo != null && other.GitRepo == null) return false;
        if (!f.apply(this.GitRepo, other.GitRepo)) return false;
      }
    }
    {
      Function3<AutogenPathDatasetComponentDiff, AutogenPathDatasetComponentDiff, Boolean> f =
          (x, y) -> x.equals(y);
      if (this.Path != null || other.Path != null) {
        if (this.Path == null && other.Path != null) return false;
        if (this.Path != null && other.Path == null) return false;
        if (!f.apply(this.Path, other.Path)) return false;
      }
    }
    return true;
  }

  public AutogenNotebookCodeDiff setGitRepo(AutogenGitCodeDiff value) {
    this.GitRepo = Utils.removeEmpty(value);
    return this;
  }

  public AutogenGitCodeDiff getGitRepo() {
    return this.GitRepo;
  }

  public AutogenNotebookCodeDiff setPath(AutogenPathDatasetComponentDiff value) {
    this.Path = Utils.removeEmpty(value);
    return this;
  }

  public AutogenPathDatasetComponentDiff getPath() {
    return this.Path;
  }

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

    AutogenNotebookCodeDiff obj = new AutogenNotebookCodeDiff();
    {
      Function<ai.verta.modeldb.versioning.NotebookCodeDiff, AutogenGitCodeDiff> f =
          x -> AutogenGitCodeDiff.fromProto(blob.getGitRepo());
      obj.setGitRepo(f.apply(blob));
    }
    {
      Function<ai.verta.modeldb.versioning.NotebookCodeDiff, AutogenPathDatasetComponentDiff> f =
          x -> AutogenPathDatasetComponentDiff.fromProto(blob.getPath());
      obj.setPath(f.apply(blob));
    }
    return obj;
  }

  public ai.verta.modeldb.versioning.NotebookCodeDiff.Builder toProto() {
    ai.verta.modeldb.versioning.NotebookCodeDiff.Builder builder =
        ai.verta.modeldb.versioning.NotebookCodeDiff.newBuilder();
    {
      if (this.GitRepo != null && !this.GitRepo.equals(null)) {
        Function<ai.verta.modeldb.versioning.NotebookCodeDiff.Builder, Void> f =
            x -> {
              builder.setGitRepo(this.GitRepo.toProto());
              return null;
            };
        f.apply(builder);
      }
    }
    {
      if (this.Path != null && !this.Path.equals(null)) {
        Function<ai.verta.modeldb.versioning.NotebookCodeDiff.Builder, Void> f =
            x -> {
              builder.setPath(this.Path.toProto());
              return null;
            };
        f.apply(builder);
      }
    }
    return builder;
  }

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

  public void preVisitDeep(Visitor visitor) throws ModelDBException {
    this.preVisitShallow(visitor);
    visitor.preVisitDeepAutogenGitCodeDiff(this.GitRepo);
    visitor.preVisitDeepAutogenPathDatasetComponentDiff(this.Path);
  }

  public AutogenNotebookCodeDiff postVisitShallow(Visitor visitor) throws ModelDBException {
    return visitor.postVisitAutogenNotebookCodeDiff(this);
  }

  public AutogenNotebookCodeDiff postVisitDeep(Visitor visitor) throws ModelDBException {
    this.setGitRepo(visitor.postVisitDeepAutogenGitCodeDiff(this.GitRepo));
    this.setPath(visitor.postVisitDeepAutogenPathDatasetComponentDiff(this.Path));
    return this.postVisitShallow(visitor);
  }
}
