// Automatically generated by xdrgen
// DO NOT EDIT or your changes may be overwritten

package org.stellar.sdk.xdr;

import com.google.common.base.Objects;
import java.io.IOException;
import java.util.Arrays;

// === xdr source ============================================================

//  struct LedgerSCPMessages
//  {
//      uint32 ledgerSeq;
//      SCPEnvelope messages<>;
//  };

//  ===========================================================================
public class LedgerSCPMessages implements XdrElement {
  public LedgerSCPMessages() {}

  private Uint32 ledgerSeq;

  public Uint32 getLedgerSeq() {
    return this.ledgerSeq;
  }

  public void setLedgerSeq(Uint32 value) {
    this.ledgerSeq = value;
  }

  private SCPEnvelope[] messages;

  public SCPEnvelope[] getMessages() {
    return this.messages;
  }

  public void setMessages(SCPEnvelope[] value) {
    this.messages = value;
  }

  public static void encode(XdrDataOutputStream stream, LedgerSCPMessages encodedLedgerSCPMessages)
      throws IOException {
    Uint32.encode(stream, encodedLedgerSCPMessages.ledgerSeq);
    int messagessize = encodedLedgerSCPMessages.getMessages().length;
    stream.writeInt(messagessize);
    for (int i = 0; i < messagessize; i++) {
      SCPEnvelope.encode(stream, encodedLedgerSCPMessages.messages[i]);
    }
  }

  public void encode(XdrDataOutputStream stream) throws IOException {
    encode(stream, this);
  }

  public static LedgerSCPMessages decode(XdrDataInputStream stream) throws IOException {
    LedgerSCPMessages decodedLedgerSCPMessages = new LedgerSCPMessages();
    decodedLedgerSCPMessages.ledgerSeq = Uint32.decode(stream);
    int messagessize = stream.readInt();
    decodedLedgerSCPMessages.messages = new SCPEnvelope[messagessize];
    for (int i = 0; i < messagessize; i++) {
      decodedLedgerSCPMessages.messages[i] = SCPEnvelope.decode(stream);
    }
    return decodedLedgerSCPMessages;
  }

  @Override
  public int hashCode() {
    return Objects.hashCode(this.ledgerSeq, Arrays.hashCode(this.messages));
  }

  @Override
  public boolean equals(Object object) {
    if (!(object instanceof LedgerSCPMessages)) {
      return false;
    }

    LedgerSCPMessages other = (LedgerSCPMessages) object;
    return Objects.equal(this.ledgerSeq, other.ledgerSeq)
        && Arrays.equals(this.messages, other.messages);
  }

  public static final class Builder {
    private Uint32 ledgerSeq;
    private SCPEnvelope[] messages;

    public Builder ledgerSeq(Uint32 ledgerSeq) {
      this.ledgerSeq = ledgerSeq;
      return this;
    }

    public Builder messages(SCPEnvelope[] messages) {
      this.messages = messages;
      return this;
    }

    public LedgerSCPMessages build() {
      LedgerSCPMessages val = new LedgerSCPMessages();
      val.setLedgerSeq(ledgerSeq);
      val.setMessages(messages);
      return val;
    }
  }
}
