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

import com.squareup.wire.EnumAdapter;
import com.squareup.wire.FieldEncoding;
import com.squareup.wire.Message;
import com.squareup.wire.ProtoAdapter;
import com.squareup.wire.ProtoReader;
import com.squareup.wire.ProtoWriter;
import com.squareup.wire.ReverseProtoWriter;
import com.squareup.wire.Syntax;
import com.squareup.wire.WireEnum;
import com.squareup.wire.WireField;
import com.squareup.wire.internal.Internal;
import java.io.IOException;
import java.lang.Integer;
import java.lang.Long;
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 MappyTwo extends Message<MappyTwo, MappyTwo.Builder> {
  public static final ProtoAdapter<MappyTwo> ADAPTER = new ProtoAdapter_MappyTwo();

  private static final long serialVersionUID = 0L;

  @WireField(
      tag = 1,
      keyAdapter = "com.squareup.wire.ProtoAdapter#STRING",
      adapter = "com.squareup.wire.map.MappyTwo$ValueEnum#ADAPTER"
  )
  public final Map<String, ValueEnum> string_enums;

  @WireField(
      tag = 2,
      keyAdapter = "com.squareup.wire.ProtoAdapter#SINT64",
      adapter = "com.squareup.wire.map.Thing#ADAPTER"
  )
  public final Map<Long, Thing> int_things;

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

  @WireField(
      tag = 4,
      keyAdapter = "com.squareup.wire.ProtoAdapter#SINT32",
      adapter = "com.squareup.wire.map.Thing#ADAPTER"
  )
  public final Map<Integer, Thing> int_things_two;

  public MappyTwo(Map<String, ValueEnum> string_enums, Map<Long, Thing> int_things,
      Map<String, Long> string_ints, Map<Integer, Thing> int_things_two) {
    this(string_enums, int_things, string_ints, int_things_two, ByteString.EMPTY);
  }

  public MappyTwo(Map<String, ValueEnum> string_enums, Map<Long, Thing> int_things,
      Map<String, Long> string_ints, Map<Integer, Thing> int_things_two, ByteString unknownFields) {
    super(ADAPTER, unknownFields);
    this.string_enums = Internal.immutableCopyOf("string_enums", string_enums);
    this.int_things = Internal.immutableCopyOf("int_things", int_things);
    this.string_ints = Internal.immutableCopyOf("string_ints", string_ints);
    this.int_things_two = Internal.immutableCopyOf("int_things_two", int_things_two);
  }

  @Override
  public Builder newBuilder() {
    Builder builder = new Builder();
    builder.string_enums = Internal.copyOf(string_enums);
    builder.int_things = Internal.copyOf(int_things);
    builder.string_ints = Internal.copyOf(string_ints);
    builder.int_things_two = Internal.copyOf(int_things_two);
    builder.addUnknownFields(unknownFields());
    return builder;
  }

  @Override
  public boolean equals(Object other) {
    if (other == this) return true;
    if (!(other instanceof MappyTwo)) return false;
    MappyTwo o = (MappyTwo) other;
    return unknownFields().equals(o.unknownFields())
        && string_enums.equals(o.string_enums)
        && int_things.equals(o.int_things)
        && string_ints.equals(o.string_ints)
        && int_things_two.equals(o.int_things_two);
  }

  @Override
  public int hashCode() {
    int result = super.hashCode;
    if (result == 0) {
      result = unknownFields().hashCode();
      result = result * 37 + string_enums.hashCode();
      result = result * 37 + int_things.hashCode();
      result = result * 37 + string_ints.hashCode();
      result = result * 37 + int_things_two.hashCode();
      super.hashCode = result;
    }
    return result;
  }

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    if (!string_enums.isEmpty()) builder.append(", string_enums=").append(string_enums);
    if (!int_things.isEmpty()) builder.append(", int_things=").append(int_things);
    if (!string_ints.isEmpty()) builder.append(", string_ints=").append(string_ints);
    if (!int_things_two.isEmpty()) builder.append(", int_things_two=").append(int_things_two);
    return builder.replace(0, 2, "MappyTwo{").append('}').toString();
  }

  public static final class Builder extends Message.Builder<MappyTwo, Builder> {
    public Map<String, ValueEnum> string_enums;

    public Map<Long, Thing> int_things;

    public Map<String, Long> string_ints;

    public Map<Integer, Thing> int_things_two;

    public Builder() {
      string_enums = Internal.newMutableMap();
      int_things = Internal.newMutableMap();
      string_ints = Internal.newMutableMap();
      int_things_two = Internal.newMutableMap();
    }

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

    public Builder int_things(Map<Long, Thing> int_things) {
      Internal.checkElementsNotNull(int_things);
      this.int_things = int_things;
      return this;
    }

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

    public Builder int_things_two(Map<Integer, Thing> int_things_two) {
      Internal.checkElementsNotNull(int_things_two);
      this.int_things_two = int_things_two;
      return this;
    }

    @Override
    public MappyTwo build() {
      return new MappyTwo(string_enums, int_things, string_ints, int_things_two, super.buildUnknownFields());
    }
  }

  public enum ValueEnum implements WireEnum {
    DEFAULT(0),

    FOO(1),

    BAR(2);

    public static final ProtoAdapter<ValueEnum> ADAPTER = new ProtoAdapter_ValueEnum();

    private final int value;

    ValueEnum(int value) {
      this.value = value;
    }

    /**
     * Return the constant for {@code value} or null.
     */
    public static ValueEnum fromValue(int value) {
      switch (value) {
        case 0: return DEFAULT;
        case 1: return FOO;
        case 2: return BAR;
        default: return null;
      }
    }

    @Override
    public int getValue() {
      return value;
    }

    private static final class ProtoAdapter_ValueEnum extends EnumAdapter<ValueEnum> {
      ProtoAdapter_ValueEnum() {
        super(ValueEnum.class, Syntax.PROTO_2, ValueEnum.DEFAULT);
      }

      @Override
      protected ValueEnum fromValue(int value) {
        return ValueEnum.fromValue(value);
      }
    }
  }

  private static final class ProtoAdapter_MappyTwo extends ProtoAdapter<MappyTwo> {
    private ProtoAdapter<Map<String, ValueEnum>> string_enums;

    private ProtoAdapter<Map<Long, Thing>> int_things;

    private ProtoAdapter<Map<String, Long>> string_ints;

    private ProtoAdapter<Map<Integer, Thing>> int_things_two;

    public ProtoAdapter_MappyTwo() {
      super(FieldEncoding.LENGTH_DELIMITED, MappyTwo.class, "type.googleapis.com/com.squareup.wire.map.MappyTwo", Syntax.PROTO_2, null, "map.proto");
    }

    @Override
    public int encodedSize(MappyTwo value) {
      int result = 0;
      result += string_enumsAdapter().encodedSizeWithTag(1, value.string_enums);
      result += int_thingsAdapter().encodedSizeWithTag(2, value.int_things);
      result += string_intsAdapter().encodedSizeWithTag(3, value.string_ints);
      result += int_things_twoAdapter().encodedSizeWithTag(4, value.int_things_two);
      result += value.unknownFields().size();
      return result;
    }

    @Override
    public void encode(ProtoWriter writer, MappyTwo value) throws IOException {
      string_enumsAdapter().encodeWithTag(writer, 1, value.string_enums);
      int_thingsAdapter().encodeWithTag(writer, 2, value.int_things);
      string_intsAdapter().encodeWithTag(writer, 3, value.string_ints);
      int_things_twoAdapter().encodeWithTag(writer, 4, value.int_things_two);
      writer.writeBytes(value.unknownFields());
    }

    @Override
    public void encode(ReverseProtoWriter writer, MappyTwo value) throws IOException {
      writer.writeBytes(value.unknownFields());
      int_things_twoAdapter().encodeWithTag(writer, 4, value.int_things_two);
      string_intsAdapter().encodeWithTag(writer, 3, value.string_ints);
      int_thingsAdapter().encodeWithTag(writer, 2, value.int_things);
      string_enumsAdapter().encodeWithTag(writer, 1, value.string_enums);
    }

    @Override
    public MappyTwo 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.string_enums.putAll(string_enumsAdapter().decode(reader)); break;
          case 2: builder.int_things.putAll(int_thingsAdapter().decode(reader)); break;
          case 3: builder.string_ints.putAll(string_intsAdapter().decode(reader)); break;
          case 4: builder.int_things_two.putAll(int_things_twoAdapter().decode(reader)); break;
          default: {
            reader.readUnknownField(tag);
          }
        }
      }
      builder.addUnknownFields(reader.endMessageAndGetUnknownFields(token));
      return builder.build();
    }

    @Override
    public MappyTwo redact(MappyTwo value) {
      Builder builder = value.newBuilder();
      Internal.redactElements(builder.int_things, Thing.ADAPTER);
      Internal.redactElements(builder.int_things_two, Thing.ADAPTER);
      builder.clearUnknownFields();
      return builder.build();
    }

    private ProtoAdapter<Map<String, ValueEnum>> string_enumsAdapter() {
      ProtoAdapter<Map<String, ValueEnum>> result = string_enums;
      if (result == null) {
        result = ProtoAdapter.newMapAdapter(ProtoAdapter.STRING, ValueEnum.ADAPTER);
        string_enums = result;
      }
      return result;
    }

    private ProtoAdapter<Map<Long, Thing>> int_thingsAdapter() {
      ProtoAdapter<Map<Long, Thing>> result = int_things;
      if (result == null) {
        result = ProtoAdapter.newMapAdapter(ProtoAdapter.SINT64, Thing.ADAPTER);
        int_things = result;
      }
      return result;
    }

    private ProtoAdapter<Map<String, Long>> string_intsAdapter() {
      ProtoAdapter<Map<String, Long>> result = string_ints;
      if (result == null) {
        result = ProtoAdapter.newMapAdapter(ProtoAdapter.STRING, ProtoAdapter.SINT64);
        string_ints = result;
      }
      return result;
    }

    private ProtoAdapter<Map<Integer, Thing>> int_things_twoAdapter() {
      ProtoAdapter<Map<Integer, Thing>> result = int_things_two;
      if (result == null) {
        result = ProtoAdapter.newMapAdapter(ProtoAdapter.SINT32, Thing.ADAPTER);
        int_things_two = result;
      }
      return result;
    }
  }
}
