/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package com.vesoft.nebula.meta;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import java.util.BitSet;
import java.util.Arrays;
import com.facebook.thrift.*;
import com.facebook.thrift.annotations.*;
import com.facebook.thrift.async.*;
import com.facebook.thrift.meta_data.*;
import com.facebook.thrift.server.*;
import com.facebook.thrift.transport.*;
import com.facebook.thrift.protocol.*;

@SuppressWarnings({ "unused", "serial" })
public class CreateSessionReq implements TBase, java.io.Serializable, Cloneable, Comparable<CreateSessionReq> {
  private static final TStruct STRUCT_DESC = new TStruct("CreateSessionReq");
  private static final TField USER_FIELD_DESC = new TField("user", TType.STRING, (short)1);
  private static final TField GRAPH_ADDR_FIELD_DESC = new TField("graph_addr", TType.STRUCT, (short)2);
  private static final TField CLIENT_IP_FIELD_DESC = new TField("client_ip", TType.STRING, (short)3);

  public byte[] user;
  public com.vesoft.nebula.HostAddr graph_addr;
  public byte[] client_ip;
  public static final int USER = 1;
  public static final int GRAPH_ADDR = 2;
  public static final int CLIENT_IP = 3;

  // isset id assignments

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(USER, new FieldMetaData("user", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(GRAPH_ADDR, new FieldMetaData("graph_addr", TFieldRequirementType.DEFAULT, 
        new StructMetaData(TType.STRUCT, com.vesoft.nebula.HostAddr.class)));
    tmpMetaDataMap.put(CLIENT_IP, new FieldMetaData("client_ip", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

  static {
    FieldMetaData.addStructMetaDataMap(CreateSessionReq.class, metaDataMap);
  }

  public CreateSessionReq() {
  }

  public CreateSessionReq(
      byte[] user,
      com.vesoft.nebula.HostAddr graph_addr,
      byte[] client_ip) {
    this();
    this.user = user;
    this.graph_addr = graph_addr;
    this.client_ip = client_ip;
  }

  public static class Builder {
    private byte[] user;
    private com.vesoft.nebula.HostAddr graph_addr;
    private byte[] client_ip;

    public Builder() {
    }

    public Builder setUser(final byte[] user) {
      this.user = user;
      return this;
    }

    public Builder setGraph_addr(final com.vesoft.nebula.HostAddr graph_addr) {
      this.graph_addr = graph_addr;
      return this;
    }

    public Builder setClient_ip(final byte[] client_ip) {
      this.client_ip = client_ip;
      return this;
    }

    public CreateSessionReq build() {
      CreateSessionReq result = new CreateSessionReq();
      result.setUser(this.user);
      result.setGraph_addr(this.graph_addr);
      result.setClient_ip(this.client_ip);
      return result;
    }
  }

  public static Builder builder() {
    return new Builder();
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public CreateSessionReq(CreateSessionReq other) {
    if (other.isSetUser()) {
      this.user = TBaseHelper.deepCopy(other.user);
    }
    if (other.isSetGraph_addr()) {
      this.graph_addr = TBaseHelper.deepCopy(other.graph_addr);
    }
    if (other.isSetClient_ip()) {
      this.client_ip = TBaseHelper.deepCopy(other.client_ip);
    }
  }

  public CreateSessionReq deepCopy() {
    return new CreateSessionReq(this);
  }

  public byte[] getUser() {
    return this.user;
  }

  public CreateSessionReq setUser(byte[] user) {
    this.user = user;
    return this;
  }

  public void unsetUser() {
    this.user = null;
  }

  // Returns true if field user is set (has been assigned a value) and false otherwise
  public boolean isSetUser() {
    return this.user != null;
  }

  public void setUserIsSet(boolean __value) {
    if (!__value) {
      this.user = null;
    }
  }

  public com.vesoft.nebula.HostAddr getGraph_addr() {
    return this.graph_addr;
  }

  public CreateSessionReq setGraph_addr(com.vesoft.nebula.HostAddr graph_addr) {
    this.graph_addr = graph_addr;
    return this;
  }

  public void unsetGraph_addr() {
    this.graph_addr = null;
  }

  // Returns true if field graph_addr is set (has been assigned a value) and false otherwise
  public boolean isSetGraph_addr() {
    return this.graph_addr != null;
  }

  public void setGraph_addrIsSet(boolean __value) {
    if (!__value) {
      this.graph_addr = null;
    }
  }

  public byte[] getClient_ip() {
    return this.client_ip;
  }

  public CreateSessionReq setClient_ip(byte[] client_ip) {
    this.client_ip = client_ip;
    return this;
  }

  public void unsetClient_ip() {
    this.client_ip = null;
  }

  // Returns true if field client_ip is set (has been assigned a value) and false otherwise
  public boolean isSetClient_ip() {
    return this.client_ip != null;
  }

  public void setClient_ipIsSet(boolean __value) {
    if (!__value) {
      this.client_ip = null;
    }
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case USER:
      if (__value == null) {
        unsetUser();
      } else {
        setUser((byte[])__value);
      }
      break;

    case GRAPH_ADDR:
      if (__value == null) {
        unsetGraph_addr();
      } else {
        setGraph_addr((com.vesoft.nebula.HostAddr)__value);
      }
      break;

    case CLIENT_IP:
      if (__value == null) {
        unsetClient_ip();
      } else {
        setClient_ip((byte[])__value);
      }
      break;

    default:
      throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
    }
  }

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case USER:
      return getUser();

    case GRAPH_ADDR:
      return getGraph_addr();

    case CLIENT_IP:
      return getClient_ip();

    default:
      throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
    }
  }

  @Override
  public boolean equals(Object _that) {
    if (_that == null)
      return false;
    if (this == _that)
      return true;
    if (!(_that instanceof CreateSessionReq))
      return false;
    CreateSessionReq that = (CreateSessionReq)_that;

    if (!TBaseHelper.equalsSlow(this.isSetUser(), that.isSetUser(), this.user, that.user)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetGraph_addr(), that.isSetGraph_addr(), this.graph_addr, that.graph_addr)) { return false; }

    if (!TBaseHelper.equalsSlow(this.isSetClient_ip(), that.isSetClient_ip(), this.client_ip, that.client_ip)) { return false; }

    return true;
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {user, graph_addr, client_ip});
  }

  @Override
  public int compareTo(CreateSessionReq other) {
    if (other == null) {
      // See java.lang.Comparable docs
      throw new NullPointerException();
    }

    if (other == this) {
      return 0;
    }
    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetUser()).compareTo(other.isSetUser());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(user, other.user);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetGraph_addr()).compareTo(other.isSetGraph_addr());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(graph_addr, other.graph_addr);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetClient_ip()).compareTo(other.isSetClient_ip());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(client_ip, other.client_ip);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    return 0;
  }

  public void read(TProtocol iprot) throws TException {
    TField __field;
    iprot.readStructBegin(metaDataMap);
    while (true)
    {
      __field = iprot.readFieldBegin();
      if (__field.type == TType.STOP) { 
        break;
      }
      switch (__field.id)
      {
        case USER:
          if (__field.type == TType.STRING) {
            this.user = iprot.readBinary();
          } else { 
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case GRAPH_ADDR:
          if (__field.type == TType.STRUCT) {
            this.graph_addr = new com.vesoft.nebula.HostAddr();
            this.graph_addr.read(iprot);
          } else { 
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case CLIENT_IP:
          if (__field.type == TType.STRING) {
            this.client_ip = iprot.readBinary();
          } else { 
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        default:
          TProtocolUtil.skip(iprot, __field.type);
          break;
      }
      iprot.readFieldEnd();
    }
    iprot.readStructEnd();


    // check for required fields of primitive type, which can't be checked in the validate method
    validate();
  }

  public void write(TProtocol oprot) throws TException {
    validate();

    oprot.writeStructBegin(STRUCT_DESC);
    if (this.user != null) {
      oprot.writeFieldBegin(USER_FIELD_DESC);
      oprot.writeBinary(this.user);
      oprot.writeFieldEnd();
    }
    if (this.graph_addr != null) {
      oprot.writeFieldBegin(GRAPH_ADDR_FIELD_DESC);
      this.graph_addr.write(oprot);
      oprot.writeFieldEnd();
    }
    if (this.client_ip != null) {
      oprot.writeFieldBegin(CLIENT_IP_FIELD_DESC);
      oprot.writeBinary(this.client_ip);
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

  @Override
  public String toString() {
    return toString(1, true);
  }

  @Override
  public String toString(int indent, boolean prettyPrint) {
    String indentStr = prettyPrint ? TBaseHelper.getIndentedString(indent) : "";
    String newLine = prettyPrint ? "\n" : "";
    String space = prettyPrint ? " " : "";
    StringBuilder sb = new StringBuilder("CreateSessionReq");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("user");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getUser() == null) {
      sb.append("null");
    } else {
        int __user_size = Math.min(this.getUser().length, 128);
        for (int i = 0; i < __user_size; i++) {
          if (i != 0) sb.append(" ");
          sb.append(Integer.toHexString(this.getUser()[i]).length() > 1 ? Integer.toHexString(this.getUser()[i]).substring(Integer.toHexString(this.getUser()[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.getUser()[i]).toUpperCase());
        }
        if (this.getUser().length > 128) sb.append(" ...");
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("graph_addr");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getGraph_addr() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getGraph_addr(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("client_ip");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getClient_ip() == null) {
      sb.append("null");
    } else {
        int __client_ip_size = Math.min(this.getClient_ip().length, 128);
        for (int i = 0; i < __client_ip_size; i++) {
          if (i != 0) sb.append(" ");
          sb.append(Integer.toHexString(this.getClient_ip()[i]).length() > 1 ? Integer.toHexString(this.getClient_ip()[i]).substring(Integer.toHexString(this.getClient_ip()[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.getClient_ip()[i]).toUpperCase());
        }
        if (this.getClient_ip().length > 128) sb.append(" ...");
    }
    first = false;
    sb.append(newLine + TBaseHelper.reduceIndent(indentStr));
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws TException {
    // check for required fields
  }

}

