/**
 * 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 ConfigItem implements TBase, java.io.Serializable, Cloneable {
  private static final TStruct STRUCT_DESC = new TStruct("ConfigItem");
  private static final TField MODULE_FIELD_DESC = new TField("module", TType.I32, (short)1);
  private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short)2);
  private static final TField MODE_FIELD_DESC = new TField("mode", TType.I32, (short)3);
  private static final TField VALUE_FIELD_DESC = new TField("value", TType.STRUCT, (short)4);

  /**
   * 
   * @see ConfigModule
   */
  public ConfigModule module;
  public byte[] name;
  /**
   * 
   * @see ConfigMode
   */
  public ConfigMode mode;
  public com.vesoft.nebula.Value value;
  public static final int MODULE = 1;
  public static final int NAME = 2;
  public static final int MODE = 3;
  public static final int VALUE = 4;

  // isset id assignments

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(MODULE, new FieldMetaData("module", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I32)));
    tmpMetaDataMap.put(NAME, new FieldMetaData("name", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(MODE, new FieldMetaData("mode", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I32)));
    tmpMetaDataMap.put(VALUE, new FieldMetaData("value", TFieldRequirementType.DEFAULT, 
        new StructMetaData(TType.STRUCT, com.vesoft.nebula.Value.class)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public ConfigItem() {
  }

  public ConfigItem(
      ConfigModule module,
      byte[] name,
      ConfigMode mode,
      com.vesoft.nebula.Value value) {
    this();
    this.module = module;
    this.name = name;
    this.mode = mode;
    this.value = value;
  }

  public static class Builder {
    private ConfigModule module;
    private byte[] name;
    private ConfigMode mode;
    private com.vesoft.nebula.Value value;

    public Builder() {
    }

    public Builder setModule(final ConfigModule module) {
      this.module = module;
      return this;
    }

    public Builder setName(final byte[] name) {
      this.name = name;
      return this;
    }

    public Builder setMode(final ConfigMode mode) {
      this.mode = mode;
      return this;
    }

    public Builder setValue(final com.vesoft.nebula.Value value) {
      this.value = value;
      return this;
    }

    public ConfigItem build() {
      ConfigItem result = new ConfigItem();
      result.setModule(this.module);
      result.setName(this.name);
      result.setMode(this.mode);
      result.setValue(this.value);
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public ConfigItem(ConfigItem other) {
    if (other.isSetModule()) {
      this.module = TBaseHelper.deepCopy(other.module);
    }
    if (other.isSetName()) {
      this.name = TBaseHelper.deepCopy(other.name);
    }
    if (other.isSetMode()) {
      this.mode = TBaseHelper.deepCopy(other.mode);
    }
    if (other.isSetValue()) {
      this.value = TBaseHelper.deepCopy(other.value);
    }
  }

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

  /**
   * 
   * @see ConfigModule
   */
  public ConfigModule getModule() {
    return this.module;
  }

  /**
   * 
   * @see ConfigModule
   */
  public ConfigItem setModule(ConfigModule module) {
    this.module = module;
    return this;
  }

  public void unsetModule() {
    this.module = null;
  }

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

  public void setModuleIsSet(boolean __value) {
    if (!__value) {
      this.module = null;
    }
  }

  public byte[] getName() {
    return this.name;
  }

  public ConfigItem setName(byte[] name) {
    this.name = name;
    return this;
  }

  public void unsetName() {
    this.name = null;
  }

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

  public void setNameIsSet(boolean __value) {
    if (!__value) {
      this.name = null;
    }
  }

  /**
   * 
   * @see ConfigMode
   */
  public ConfigMode getMode() {
    return this.mode;
  }

  /**
   * 
   * @see ConfigMode
   */
  public ConfigItem setMode(ConfigMode mode) {
    this.mode = mode;
    return this;
  }

  public void unsetMode() {
    this.mode = null;
  }

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

  public void setModeIsSet(boolean __value) {
    if (!__value) {
      this.mode = null;
    }
  }

  public com.vesoft.nebula.Value getValue() {
    return this.value;
  }

  public ConfigItem setValue(com.vesoft.nebula.Value value) {
    this.value = value;
    return this;
  }

  public void unsetValue() {
    this.value = null;
  }

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

  public void setValueIsSet(boolean __value) {
    if (!__value) {
      this.value = null;
    }
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case MODULE:
      if (__value == null) {
        unsetModule();
      } else {
        setModule((ConfigModule)__value);
      }
      break;

    case NAME:
      if (__value == null) {
        unsetName();
      } else {
        setName((byte[])__value);
      }
      break;

    case MODE:
      if (__value == null) {
        unsetMode();
      } else {
        setMode((ConfigMode)__value);
      }
      break;

    case VALUE:
      if (__value == null) {
        unsetValue();
      } else {
        setValue((com.vesoft.nebula.Value)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case MODULE:
      return getModule();

    case NAME:
      return getName();

    case MODE:
      return getMode();

    case VALUE:
      return getValue();

    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 ConfigItem))
      return false;
    ConfigItem that = (ConfigItem)_that;

    if (!TBaseHelper.equalsNobinary(this.isSetModule(), that.isSetModule(), this.module, that.module)) { return false; }

    if (!TBaseHelper.equalsSlow(this.isSetName(), that.isSetName(), this.name, that.name)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetMode(), that.isSetMode(), this.mode, that.mode)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetValue(), that.isSetValue(), this.value, that.value)) { return false; }

    return true;
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {module, name, mode, value});
  }

  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 MODULE:
          if (__field.type == TType.I32) {
            this.module = ConfigModule.findByValue(iprot.readI32());
          } else { 
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case NAME:
          if (__field.type == TType.STRING) {
            this.name = iprot.readBinary();
          } else { 
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case MODE:
          if (__field.type == TType.I32) {
            this.mode = ConfigMode.findByValue(iprot.readI32());
          } else { 
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case VALUE:
          if (__field.type == TType.STRUCT) {
            this.value = new com.vesoft.nebula.Value();
            this.value.read(iprot);
          } 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.module != null) {
      oprot.writeFieldBegin(MODULE_FIELD_DESC);
      oprot.writeI32(this.module == null ? 0 : this.module.getValue());
      oprot.writeFieldEnd();
    }
    if (this.name != null) {
      oprot.writeFieldBegin(NAME_FIELD_DESC);
      oprot.writeBinary(this.name);
      oprot.writeFieldEnd();
    }
    if (this.mode != null) {
      oprot.writeFieldBegin(MODE_FIELD_DESC);
      oprot.writeI32(this.mode == null ? 0 : this.mode.getValue());
      oprot.writeFieldEnd();
    }
    if (this.value != null) {
      oprot.writeFieldBegin(VALUE_FIELD_DESC);
      this.value.write(oprot);
      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("ConfigItem");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("module");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getModule() == null) {
      sb.append("null");
    } else {
      String module_name = this.getModule() == null ? "null" : this.getModule().name();
      if (module_name != null) {
        sb.append(module_name);
        sb.append(" (");
      }
      sb.append(this.getModule());
      if (module_name != null) {
        sb.append(")");
      }
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("name");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getName() == null) {
      sb.append("null");
    } else {
        int __name_size = Math.min(this.getName().length, 128);
        for (int i = 0; i < __name_size; i++) {
          if (i != 0) sb.append(" ");
          sb.append(Integer.toHexString(this.getName()[i]).length() > 1 ? Integer.toHexString(this.getName()[i]).substring(Integer.toHexString(this.getName()[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.getName()[i]).toUpperCase());
        }
        if (this.getName().length > 128) sb.append(" ...");
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("mode");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getMode() == null) {
      sb.append("null");
    } else {
      String mode_name = this.getMode() == null ? "null" : this.getMode().name();
      if (mode_name != null) {
        sb.append(mode_name);
        sb.append(" (");
      }
      sb.append(this.getMode());
      if (mode_name != null) {
        sb.append(")");
      }
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("value");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getValue() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getValue(), indent + 1, prettyPrint));
    }
    first = false;
    sb.append(newLine + TBaseHelper.reduceIndent(indentStr));
    sb.append(")");
    return sb.toString();
  }

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

}

