// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: gtfs-realtime.proto
package com.google.transit.realtime;

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.WireField;
import com.squareup.wire.internal.Internal;
import java.io.IOException;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.lang.StringBuilder;
import java.util.List;
import okio.ByteString;

/**
 * An internationalized message containing per-language versions of a snippet of
 * text or a URL.
 * One of the strings from a message will be picked up. The resolution proceeds
 * as follows:
 * 1. If the UI language matches the language code of a translation,
 *    the first matching translation is picked.
 * 2. If a default UI language (e.g., English) matches the language code of a
 *    translation, the first matching translation is picked.
 * 3. If some translation has an unspecified language code, that translation is
 *    picked.
 */
public final class TranslatedString extends Message<TranslatedString, TranslatedString.Builder> {
  public static final ProtoAdapter<TranslatedString> ADAPTER = new ProtoAdapter_TranslatedString();

  private static final long serialVersionUID = 0L;

  /**
   * At least one translation must be provided.
   */
  @WireField(
      tag = 1,
      adapter = "com.google.transit.realtime.TranslatedString$Translation#ADAPTER",
      label = WireField.Label.REPEATED
  )
  public final List<Translation> translation;

  public TranslatedString(List<Translation> translation) {
    this(translation, ByteString.EMPTY);
  }

  public TranslatedString(List<Translation> translation, ByteString unknownFields) {
    super(ADAPTER, unknownFields);
    this.translation = Internal.immutableCopyOf("translation", translation);
  }

  @Override
  public Builder newBuilder() {
    Builder builder = new Builder();
    builder.translation = Internal.copyOf("translation", translation);
    builder.addUnknownFields(unknownFields());
    return builder;
  }

  @Override
  public boolean equals(Object other) {
    if (other == this) return true;
    if (!(other instanceof TranslatedString)) return false;
    TranslatedString o = (TranslatedString) other;
    return unknownFields().equals(o.unknownFields())
        && translation.equals(o.translation);
  }

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

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    if (!translation.isEmpty()) builder.append(", translation=").append(translation);
    return builder.replace(0, 2, "TranslatedString{").append('}').toString();
  }

  public static final class Builder extends Message.Builder<TranslatedString, Builder> {
    public List<Translation> translation;

    public Builder() {
      translation = Internal.newMutableList();
    }

    /**
     * At least one translation must be provided.
     */
    public Builder translation(List<Translation> translation) {
      Internal.checkElementsNotNull(translation);
      this.translation = translation;
      return this;
    }

    @Override
    public TranslatedString build() {
      return new TranslatedString(translation, super.buildUnknownFields());
    }
  }

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

    private static final long serialVersionUID = 0L;

    public static final String DEFAULT_TEXT = "";

    public static final String DEFAULT_LANGUAGE = "";

    /**
     * A UTF-8 string containing the message.
     */
    @WireField(
        tag = 1,
        adapter = "com.squareup.wire.ProtoAdapter#STRING",
        label = WireField.Label.REQUIRED
    )
    public final String text;

    /**
     * BCP-47 language code. Can be omitted if the language is unknown or if
     * no i18n is done at all for the feed. At most one translation is
     * allowed to have an unspecified language tag.
     */
    @WireField(
        tag = 2,
        adapter = "com.squareup.wire.ProtoAdapter#STRING"
    )
    public final String language;

    public Translation(String text, String language) {
      this(text, language, ByteString.EMPTY);
    }

    public Translation(String text, String language, ByteString unknownFields) {
      super(ADAPTER, unknownFields);
      this.text = text;
      this.language = language;
    }

    @Override
    public Builder newBuilder() {
      Builder builder = new Builder();
      builder.text = text;
      builder.language = language;
      builder.addUnknownFields(unknownFields());
      return builder;
    }

    @Override
    public boolean equals(Object other) {
      if (other == this) return true;
      if (!(other instanceof Translation)) return false;
      Translation o = (Translation) other;
      return unknownFields().equals(o.unknownFields())
          && text.equals(o.text)
          && Internal.equals(language, o.language);
    }

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

    @Override
    public String toString() {
      StringBuilder builder = new StringBuilder();
      builder.append(", text=").append(text);
      if (language != null) builder.append(", language=").append(language);
      return builder.replace(0, 2, "Translation{").append('}').toString();
    }

    public static final class Builder extends Message.Builder<Translation, Builder> {
      public String text;

      public String language;

      public Builder() {
      }

      /**
       * A UTF-8 string containing the message.
       */
      public Builder text(String text) {
        this.text = text;
        return this;
      }

      /**
       * BCP-47 language code. Can be omitted if the language is unknown or if
       * no i18n is done at all for the feed. At most one translation is
       * allowed to have an unspecified language tag.
       */
      public Builder language(String language) {
        this.language = language;
        return this;
      }

      @Override
      public Translation build() {
        if (text == null) {
          throw Internal.missingRequiredFields(text, "text");
        }
        return new Translation(text, language, super.buildUnknownFields());
      }
    }

    private static final class ProtoAdapter_Translation extends ProtoAdapter<Translation> {
      public ProtoAdapter_Translation() {
        super(FieldEncoding.LENGTH_DELIMITED, Translation.class);
      }

      @Override
      public int encodedSize(Translation value) {
        return ProtoAdapter.STRING.encodedSizeWithTag(1, value.text)
            + ProtoAdapter.STRING.encodedSizeWithTag(2, value.language)
            + value.unknownFields().size();
      }

      @Override
      public void encode(ProtoWriter writer, Translation value) throws IOException {
        ProtoAdapter.STRING.encodeWithTag(writer, 1, value.text);
        ProtoAdapter.STRING.encodeWithTag(writer, 2, value.language);
        writer.writeBytes(value.unknownFields());
      }

      @Override
      public Translation 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.text(ProtoAdapter.STRING.decode(reader)); break;
            case 2: builder.language(ProtoAdapter.STRING.decode(reader)); break;
            default: {
              FieldEncoding fieldEncoding = reader.peekFieldEncoding();
              Object value = fieldEncoding.rawProtoAdapter().decode(reader);
              builder.addUnknownField(tag, fieldEncoding, value);
            }
          }
        }
        reader.endMessage(token);
        return builder.build();
      }

      @Override
      public Translation redact(Translation value) {
        Builder builder = value.newBuilder();
        builder.clearUnknownFields();
        return builder.build();
      }
    }
  }

  private static final class ProtoAdapter_TranslatedString extends ProtoAdapter<TranslatedString> {
    public ProtoAdapter_TranslatedString() {
      super(FieldEncoding.LENGTH_DELIMITED, TranslatedString.class);
    }

    @Override
    public int encodedSize(TranslatedString value) {
      return Translation.ADAPTER.asRepeated().encodedSizeWithTag(1, value.translation)
          + value.unknownFields().size();
    }

    @Override
    public void encode(ProtoWriter writer, TranslatedString value) throws IOException {
      Translation.ADAPTER.asRepeated().encodeWithTag(writer, 1, value.translation);
      writer.writeBytes(value.unknownFields());
    }

    @Override
    public TranslatedString 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.translation.add(Translation.ADAPTER.decode(reader)); break;
          default: {
            FieldEncoding fieldEncoding = reader.peekFieldEncoding();
            Object value = fieldEncoding.rawProtoAdapter().decode(reader);
            builder.addUnknownField(tag, fieldEncoding, value);
          }
        }
      }
      reader.endMessage(token);
      return builder.build();
    }

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