/**
 * Autogenerated by Avro
 *
 * DO NOT EDIT DIRECTLY
 */
package com.github.diegopacheco.avro;

import org.apache.avro.generic.GenericArray;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.util.Utf8;
import org.apache.avro.message.BinaryMessageEncoder;
import org.apache.avro.message.BinaryMessageDecoder;
import org.apache.avro.message.SchemaStore;

@org.apache.avro.specific.AvroGenerated
public class AvroHttpRequest extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
  private static final long serialVersionUID = -7022430122046250369L;
  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"AvroHttpRequest\",\"namespace\":\"com.github.diegopacheco.avro\",\"fields\":[{\"name\":\"personIdentifier\",\"type\":{\"type\":\"record\",\"name\":\"PersonIdentifier\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"email\",\"type\":\"string\"}]}}]}");
  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }

  private static SpecificData MODEL$ = new SpecificData();

  private static final BinaryMessageEncoder<AvroHttpRequest> ENCODER =
      new BinaryMessageEncoder<AvroHttpRequest>(MODEL$, SCHEMA$);

  private static final BinaryMessageDecoder<AvroHttpRequest> DECODER =
      new BinaryMessageDecoder<AvroHttpRequest>(MODEL$, SCHEMA$);

  /**
   * Return the BinaryMessageEncoder instance used by this class.
   * @return the message encoder used by this class
   */
  public static BinaryMessageEncoder<AvroHttpRequest> getEncoder() {
    return ENCODER;
  }

  /**
   * Return the BinaryMessageDecoder instance used by this class.
   * @return the message decoder used by this class
   */
  public static BinaryMessageDecoder<AvroHttpRequest> getDecoder() {
    return DECODER;
  }

  /**
   * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
   * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
   * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore
   */
  public static BinaryMessageDecoder<AvroHttpRequest> createDecoder(SchemaStore resolver) {
    return new BinaryMessageDecoder<AvroHttpRequest>(MODEL$, SCHEMA$, resolver);
  }

  /**
   * Serializes this AvroHttpRequest to a ByteBuffer.
   * @return a buffer holding the serialized data for this instance
   * @throws java.io.IOException if this instance could not be serialized
   */
  public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
    return ENCODER.encode(this);
  }

  /**
   * Deserializes a AvroHttpRequest from a ByteBuffer.
   * @param b a byte buffer holding serialized data for an instance of this class
   * @return a AvroHttpRequest instance decoded from the given buffer
   * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class
   */
  public static AvroHttpRequest fromByteBuffer(
      java.nio.ByteBuffer b) throws java.io.IOException {
    return DECODER.decode(b);
  }

  @Deprecated public com.github.diegopacheco.avro.PersonIdentifier personIdentifier;

  /**
   * Default constructor.  Note that this does not initialize fields
   * to their default values from the schema.  If that is desired then
   * one should use <code>newBuilder()</code>.
   */
  public AvroHttpRequest() {}

  /**
   * All-args constructor.
   * @param personIdentifier The new value for personIdentifier
   */
  public AvroHttpRequest(com.github.diegopacheco.avro.PersonIdentifier personIdentifier) {
    this.personIdentifier = personIdentifier;
  }

  public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; }
  public org.apache.avro.Schema getSchema() { return SCHEMA$; }
  // Used by DatumWriter.  Applications should not call.
  public java.lang.Object get(int field$) {
    switch (field$) {
    case 0: return personIdentifier;
    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
    }
  }

  // Used by DatumReader.  Applications should not call.
  @SuppressWarnings(value="unchecked")
  public void put(int field$, java.lang.Object value$) {
    switch (field$) {
    case 0: personIdentifier = (com.github.diegopacheco.avro.PersonIdentifier)value$; break;
    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
    }
  }

  /**
   * Gets the value of the 'personIdentifier' field.
   * @return The value of the 'personIdentifier' field.
   */
  public com.github.diegopacheco.avro.PersonIdentifier getPersonIdentifier() {
    return personIdentifier;
  }


  /**
   * Sets the value of the 'personIdentifier' field.
   * @param value the value to set.
   */
  public void setPersonIdentifier(com.github.diegopacheco.avro.PersonIdentifier value) {
    this.personIdentifier = value;
  }

  /**
   * Creates a new AvroHttpRequest RecordBuilder.
   * @return A new AvroHttpRequest RecordBuilder
   */
  public static com.github.diegopacheco.avro.AvroHttpRequest.Builder newBuilder() {
    return new com.github.diegopacheco.avro.AvroHttpRequest.Builder();
  }

  /**
   * Creates a new AvroHttpRequest RecordBuilder by copying an existing Builder.
   * @param other The existing builder to copy.
   * @return A new AvroHttpRequest RecordBuilder
   */
  public static com.github.diegopacheco.avro.AvroHttpRequest.Builder newBuilder(com.github.diegopacheco.avro.AvroHttpRequest.Builder other) {
    if (other == null) {
      return new com.github.diegopacheco.avro.AvroHttpRequest.Builder();
    } else {
      return new com.github.diegopacheco.avro.AvroHttpRequest.Builder(other);
    }
  }

  /**
   * Creates a new AvroHttpRequest RecordBuilder by copying an existing AvroHttpRequest instance.
   * @param other The existing instance to copy.
   * @return A new AvroHttpRequest RecordBuilder
   */
  public static com.github.diegopacheco.avro.AvroHttpRequest.Builder newBuilder(com.github.diegopacheco.avro.AvroHttpRequest other) {
    if (other == null) {
      return new com.github.diegopacheco.avro.AvroHttpRequest.Builder();
    } else {
      return new com.github.diegopacheco.avro.AvroHttpRequest.Builder(other);
    }
  }

  /**
   * RecordBuilder for AvroHttpRequest instances.
   */
  @org.apache.avro.specific.AvroGenerated
  public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<AvroHttpRequest>
    implements org.apache.avro.data.RecordBuilder<AvroHttpRequest> {

    private com.github.diegopacheco.avro.PersonIdentifier personIdentifier;
    private com.github.diegopacheco.avro.PersonIdentifier.Builder personIdentifierBuilder;

    /** Creates a new Builder */
    private Builder() {
      super(SCHEMA$);
    }

    /**
     * Creates a Builder by copying an existing Builder.
     * @param other The existing Builder to copy.
     */
    private Builder(com.github.diegopacheco.avro.AvroHttpRequest.Builder other) {
      super(other);
      if (isValidValue(fields()[0], other.personIdentifier)) {
        this.personIdentifier = data().deepCopy(fields()[0].schema(), other.personIdentifier);
        fieldSetFlags()[0] = other.fieldSetFlags()[0];
      }
      if (other.hasPersonIdentifierBuilder()) {
        this.personIdentifierBuilder = com.github.diegopacheco.avro.PersonIdentifier.newBuilder(other.getPersonIdentifierBuilder());
      }
    }

    /**
     * Creates a Builder by copying an existing AvroHttpRequest instance
     * @param other The existing instance to copy.
     */
    private Builder(com.github.diegopacheco.avro.AvroHttpRequest other) {
      super(SCHEMA$);
      if (isValidValue(fields()[0], other.personIdentifier)) {
        this.personIdentifier = data().deepCopy(fields()[0].schema(), other.personIdentifier);
        fieldSetFlags()[0] = true;
      }
      this.personIdentifierBuilder = null;
    }

    /**
      * Gets the value of the 'personIdentifier' field.
      * @return The value.
      */
    public com.github.diegopacheco.avro.PersonIdentifier getPersonIdentifier() {
      return personIdentifier;
    }


    /**
      * Sets the value of the 'personIdentifier' field.
      * @param value The value of 'personIdentifier'.
      * @return This builder.
      */
    public com.github.diegopacheco.avro.AvroHttpRequest.Builder setPersonIdentifier(com.github.diegopacheco.avro.PersonIdentifier value) {
      validate(fields()[0], value);
      this.personIdentifierBuilder = null;
      this.personIdentifier = value;
      fieldSetFlags()[0] = true;
      return this;
    }

    /**
      * Checks whether the 'personIdentifier' field has been set.
      * @return True if the 'personIdentifier' field has been set, false otherwise.
      */
    public boolean hasPersonIdentifier() {
      return fieldSetFlags()[0];
    }

    /**
     * Gets the Builder instance for the 'personIdentifier' field and creates one if it doesn't exist yet.
     * @return This builder.
     */
    public com.github.diegopacheco.avro.PersonIdentifier.Builder getPersonIdentifierBuilder() {
      if (personIdentifierBuilder == null) {
        if (hasPersonIdentifier()) {
          setPersonIdentifierBuilder(com.github.diegopacheco.avro.PersonIdentifier.newBuilder(personIdentifier));
        } else {
          setPersonIdentifierBuilder(com.github.diegopacheco.avro.PersonIdentifier.newBuilder());
        }
      }
      return personIdentifierBuilder;
    }

    /**
     * Sets the Builder instance for the 'personIdentifier' field
     * @param value The builder instance that must be set.
     * @return This builder.
     */
    public com.github.diegopacheco.avro.AvroHttpRequest.Builder setPersonIdentifierBuilder(com.github.diegopacheco.avro.PersonIdentifier.Builder value) {
      clearPersonIdentifier();
      personIdentifierBuilder = value;
      return this;
    }

    /**
     * Checks whether the 'personIdentifier' field has an active Builder instance
     * @return True if the 'personIdentifier' field has an active Builder instance
     */
    public boolean hasPersonIdentifierBuilder() {
      return personIdentifierBuilder != null;
    }

    /**
      * Clears the value of the 'personIdentifier' field.
      * @return This builder.
      */
    public com.github.diegopacheco.avro.AvroHttpRequest.Builder clearPersonIdentifier() {
      personIdentifier = null;
      personIdentifierBuilder = null;
      fieldSetFlags()[0] = false;
      return this;
    }

    @Override
    @SuppressWarnings("unchecked")
    public AvroHttpRequest build() {
      try {
        AvroHttpRequest record = new AvroHttpRequest();
        if (personIdentifierBuilder != null) {
          try {
            record.personIdentifier = this.personIdentifierBuilder.build();
          } catch (org.apache.avro.AvroMissingFieldException e) {
            e.addParentField(record.getSchema().getField("personIdentifier"));
            throw e;
          }
        } else {
          record.personIdentifier = fieldSetFlags()[0] ? this.personIdentifier : (com.github.diegopacheco.avro.PersonIdentifier) defaultValue(fields()[0]);
        }
        return record;
      } catch (org.apache.avro.AvroMissingFieldException e) {
        throw e;
      } catch (java.lang.Exception e) {
        throw new org.apache.avro.AvroRuntimeException(e);
      }
    }
  }

  @SuppressWarnings("unchecked")
  private static final org.apache.avro.io.DatumWriter<AvroHttpRequest>
    WRITER$ = (org.apache.avro.io.DatumWriter<AvroHttpRequest>)MODEL$.createDatumWriter(SCHEMA$);

  @Override public void writeExternal(java.io.ObjectOutput out)
    throws java.io.IOException {
    WRITER$.write(this, SpecificData.getEncoder(out));
  }

  @SuppressWarnings("unchecked")
  private static final org.apache.avro.io.DatumReader<AvroHttpRequest>
    READER$ = (org.apache.avro.io.DatumReader<AvroHttpRequest>)MODEL$.createDatumReader(SCHEMA$);

  @Override public void readExternal(java.io.ObjectInput in)
    throws java.io.IOException {
    READER$.read(this, SpecificData.getDecoder(in));
  }

  @Override protected boolean hasCustomCoders() { return true; }

  @Override public void customEncode(org.apache.avro.io.Encoder out)
    throws java.io.IOException
  {
    this.personIdentifier.customEncode(out);

  }

  @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
    throws java.io.IOException
  {
    org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
    if (fieldOrder == null) {
      if (this.personIdentifier == null) {
        this.personIdentifier = new com.github.diegopacheco.avro.PersonIdentifier();
      }
      this.personIdentifier.customDecode(in);

    } else {
      for (int i = 0; i < 1; i++) {
        switch (fieldOrder[i].pos()) {
        case 0:
          if (this.personIdentifier == null) {
            this.personIdentifier = new com.github.diegopacheco.avro.PersonIdentifier();
          }
          this.personIdentifier.customDecode(in);
          break;

        default:
          throw new java.io.IOException("Corrupt ResolvingDecoder.");
        }
      }
    }
  }
}










