// Code generated by Wire protocol buffer compiler, do not edit.
// Source: com.squareup.wire.ModelEvaluation in recursive_map.proto
package com.squareup.wire;

import com.squareup.wire.internal.Internal;
import java.io.IOException;
import java.lang.Double;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.lang.StringBuilder;
import java.util.Map;
import okio.ByteString;

public final class ModelEvaluation extends Message<ModelEvaluation, ModelEvaluation.Builder> {
  public static final ProtoAdapter<ModelEvaluation> ADAPTER = new ProtoAdapter_ModelEvaluation();

  private static final long serialVersionUID = 0L;

  public static final String DEFAULT_NAME = "";

  public static final Double DEFAULT_SCORE = 0.0d;

  @WireField(
      tag = 1,
      adapter = "com.squareup.wire.ProtoAdapter#STRING"
  )
  public final String name;

  @WireField(
      tag = 2,
      adapter = "com.squareup.wire.ProtoAdapter#DOUBLE"
  )
  public final Double score;

  @WireField(
      tag = 3,
      keyAdapter = "com.squareup.wire.ProtoAdapter#STRING",
      adapter = "com.squareup.wire.ModelEvaluation#ADAPTER"
  )
  public final Map<String, ModelEvaluation> models;

  public ModelEvaluation(String name, Double score, Map<String, ModelEvaluation> models) {
    this(name, score, models, ByteString.EMPTY);
  }

  public ModelEvaluation(String name, Double score, Map<String, ModelEvaluation> models,
      ByteString unknownFields) {
    super(ADAPTER, unknownFields);
    this.name = name;
    this.score = score;
    this.models = Internal.immutableCopyOf("models", models);
  }

  @Override
  public Builder newBuilder() {
    Builder builder = new Builder();
    builder.name = name;
    builder.score = score;
    builder.models = Internal.copyOf(models);
    builder.addUnknownFields(unknownFields());
    return builder;
  }

  @Override
  public boolean equals(Object other) {
    if (other == this) return true;
    if (!(other instanceof ModelEvaluation)) return false;
    ModelEvaluation o = (ModelEvaluation) other;
    return unknownFields().equals(o.unknownFields())
        && Internal.equals(name, o.name)
        && Internal.equals(score, o.score)
        && models.equals(o.models);
  }

  @Override
  public int hashCode() {
    int result = super.hashCode;
    if (result == 0) {
      result = unknownFields().hashCode();
      result = result * 37 + (name != null ? name.hashCode() : 0);
      result = result * 37 + (score != null ? score.hashCode() : 0);
      result = result * 37 + models.hashCode();
      super.hashCode = result;
    }
    return result;
  }

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    if (name != null) builder.append(", name=").append(Internal.sanitize(name));
    if (score != null) builder.append(", score=").append(score);
    if (!models.isEmpty()) builder.append(", models=").append(models);
    return builder.replace(0, 2, "ModelEvaluation{").append('}').toString();
  }

  public static final class Builder extends Message.Builder<ModelEvaluation, Builder> {
    public String name;

    public Double score;

    public Map<String, ModelEvaluation> models;

    public Builder() {
      models = Internal.newMutableMap();
    }

    public Builder name(String name) {
      this.name = name;
      return this;
    }

    public Builder score(Double score) {
      this.score = score;
      return this;
    }

    public Builder models(Map<String, ModelEvaluation> models) {
      Internal.checkElementsNotNull(models);
      this.models = models;
      return this;
    }

    @Override
    public ModelEvaluation build() {
      return new ModelEvaluation(name, score, models, super.buildUnknownFields());
    }
  }

  private static final class ProtoAdapter_ModelEvaluation extends ProtoAdapter<ModelEvaluation> {
    private ProtoAdapter<Map<String, ModelEvaluation>> models;

    public ProtoAdapter_ModelEvaluation() {
      super(FieldEncoding.LENGTH_DELIMITED, ModelEvaluation.class, "type.googleapis.com/com.squareup.wire.ModelEvaluation", Syntax.PROTO_2, null, "recursive_map.proto");
    }

    @Override
    public int encodedSize(ModelEvaluation value) {
      int result = 0;
      result += ProtoAdapter.STRING.encodedSizeWithTag(1, value.name);
      result += ProtoAdapter.DOUBLE.encodedSizeWithTag(2, value.score);
      result += modelsAdapter().encodedSizeWithTag(3, value.models);
      result += value.unknownFields().size();
      return result;
    }

    @Override
    public void encode(ProtoWriter writer, ModelEvaluation value) throws IOException {
      ProtoAdapter.STRING.encodeWithTag(writer, 1, value.name);
      ProtoAdapter.DOUBLE.encodeWithTag(writer, 2, value.score);
      modelsAdapter().encodeWithTag(writer, 3, value.models);
      writer.writeBytes(value.unknownFields());
    }

    @Override
    public void encode(ReverseProtoWriter writer, ModelEvaluation value) throws IOException {
      writer.writeBytes(value.unknownFields());
      modelsAdapter().encodeWithTag(writer, 3, value.models);
      ProtoAdapter.DOUBLE.encodeWithTag(writer, 2, value.score);
      ProtoAdapter.STRING.encodeWithTag(writer, 1, value.name);
    }

    @Override
    public ModelEvaluation decode(ProtoReader reader) throws IOException {
      Builder builder = new Builder();
      long token = reader.beginMessage();
      for (int tag; (tag = reader.nextTag()) != -1;) {
        switch (tag) {
          case 1: builder.name(ProtoAdapter.STRING.decode(reader)); break;
          case 2: builder.score(ProtoAdapter.DOUBLE.decode(reader)); break;
          case 3: builder.models.putAll(modelsAdapter().decode(reader)); break;
          default: {
            reader.readUnknownField(tag);
          }
        }
      }
      builder.addUnknownFields(reader.endMessageAndGetUnknownFields(token));
      return builder.build();
    }

    @Override
    public ModelEvaluation redact(ModelEvaluation value) {
      Builder builder = value.newBuilder();
      Internal.redactElements(builder.models, ModelEvaluation.ADAPTER);
      builder.clearUnknownFields();
      return builder.build();
    }

    private ProtoAdapter<Map<String, ModelEvaluation>> modelsAdapter() {
      ProtoAdapter<Map<String, ModelEvaluation>> result = models;
      if (result == null) {
        result = ProtoAdapter.newMapAdapter(ProtoAdapter.STRING, ModelEvaluation.ADAPTER);
        models = result;
      }
      return result;
    }
  }
}
