/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package com.facebook.thrift.annotation.hack_deprecated;

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.*;

/**
 * An annotation that applies a Hack wrapper to fields, typedef or structs.
 * For example:
 * 
 *   struct User {
 *     @hack.FieldWrapper{name="MyWrapper"}
 *     1: i64 id;
 *   }
 */
@SuppressWarnings({ "unused", "serial" })
public class Wrapper implements TBase, java.io.Serializable, Cloneable, Comparable<Wrapper> {
  private static final TStruct STRUCT_DESC = new TStruct("Wrapper");
  private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short)1);
  private static final TField UNDERLYING_NAME_FIELD_DESC = new TField("underlyingName", TType.STRING, (short)2);
  private static final TField EXTRA_NAMESPACE_FIELD_DESC = new TField("extraNamespace", TType.STRING, (short)3);

  /**
   * The name of a Hack wrapper class used to wrap the field
   */
  public String name;
  /**
   * When applied directly to a typedef or struct, the IDL name of the
   * type will refer to the adapted type in Hack and the underlying thrift struct will be
   * generated in a nested namespace and/or with a different name. By default the type/struct
   * will be generated in a nested 'thrift_adapted_types' namespace with the same name,
   * but both of these can be changed by setting these fields.
   * Empty string enables the nested namespace and uses the IDL name for the struct.
   */
  public String underlyingName;
  public String extraNamespace;
  public static final int NAME = 1;
  public static final int UNDERLYINGNAME = 2;
  public static final int EXTRANAMESPACE = 3;

  // isset id assignments

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(NAME, new FieldMetaData("name", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(UNDERLYINGNAME, new FieldMetaData("underlyingName", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(EXTRANAMESPACE, new FieldMetaData("extraNamespace", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public Wrapper() {
    this.extraNamespace = "thrift_adapted_types";

  }

  public Wrapper(
      String name,
      String underlyingName,
      String extraNamespace) {
    this();
    this.name = name;
    this.underlyingName = underlyingName;
    this.extraNamespace = extraNamespace;
  }

  public static class Builder {
    private String name;
    private String underlyingName;
    private String extraNamespace;

    public Builder() {
    }

    public Builder setName(final String name) {
      this.name = name;
      return this;
    }

    public Builder setUnderlyingName(final String underlyingName) {
      this.underlyingName = underlyingName;
      return this;
    }

    public Builder setExtraNamespace(final String extraNamespace) {
      this.extraNamespace = extraNamespace;
      return this;
    }

    public Wrapper build() {
      Wrapper result = new Wrapper();
      result.setName(this.name);
      result.setUnderlyingName(this.underlyingName);
      result.setExtraNamespace(this.extraNamespace);
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public Wrapper(Wrapper other) {
    if (other.isSetName()) {
      this.name = TBaseHelper.deepCopy(other.name);
    }
    if (other.isSetUnderlyingName()) {
      this.underlyingName = TBaseHelper.deepCopy(other.underlyingName);
    }
    if (other.isSetExtraNamespace()) {
      this.extraNamespace = TBaseHelper.deepCopy(other.extraNamespace);
    }
  }

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

  /**
   * The name of a Hack wrapper class used to wrap the field
   */
  public String getName() {
    return this.name;
  }

  /**
   * The name of a Hack wrapper class used to wrap the field
   */
  public Wrapper setName(String 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;
    }
  }

  /**
   * When applied directly to a typedef or struct, the IDL name of the
   * type will refer to the adapted type in Hack and the underlying thrift struct will be
   * generated in a nested namespace and/or with a different name. By default the type/struct
   * will be generated in a nested 'thrift_adapted_types' namespace with the same name,
   * but both of these can be changed by setting these fields.
   * Empty string enables the nested namespace and uses the IDL name for the struct.
   */
  public String getUnderlyingName() {
    return this.underlyingName;
  }

  /**
   * When applied directly to a typedef or struct, the IDL name of the
   * type will refer to the adapted type in Hack and the underlying thrift struct will be
   * generated in a nested namespace and/or with a different name. By default the type/struct
   * will be generated in a nested 'thrift_adapted_types' namespace with the same name,
   * but both of these can be changed by setting these fields.
   * Empty string enables the nested namespace and uses the IDL name for the struct.
   */
  public Wrapper setUnderlyingName(String underlyingName) {
    this.underlyingName = underlyingName;
    return this;
  }

  public void unsetUnderlyingName() {
    this.underlyingName = null;
  }

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

  public void setUnderlyingNameIsSet(boolean __value) {
    if (!__value) {
      this.underlyingName = null;
    }
  }

  public String getExtraNamespace() {
    return this.extraNamespace;
  }

  public Wrapper setExtraNamespace(String extraNamespace) {
    this.extraNamespace = extraNamespace;
    return this;
  }

  public void unsetExtraNamespace() {
    this.extraNamespace = null;
  }

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

  public void setExtraNamespaceIsSet(boolean __value) {
    if (!__value) {
      this.extraNamespace = null;
    }
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case NAME:
      if (__value == null) {
        unsetName();
      } else {
        setName((String)__value);
      }
      break;

    case UNDERLYINGNAME:
      if (__value == null) {
        unsetUnderlyingName();
      } else {
        setUnderlyingName((String)__value);
      }
      break;

    case EXTRANAMESPACE:
      if (__value == null) {
        unsetExtraNamespace();
      } else {
        setExtraNamespace((String)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case NAME:
      return getName();

    case UNDERLYINGNAME:
      return getUnderlyingName();

    case EXTRANAMESPACE:
      return getExtraNamespace();

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

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

    if (!TBaseHelper.equalsNobinary(this.isSetUnderlyingName(), that.isSetUnderlyingName(), this.underlyingName, that.underlyingName)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetExtraNamespace(), that.isSetExtraNamespace(), this.extraNamespace, that.extraNamespace)) { return false; }

    return true;
  }

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

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

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

    lastComparison = Boolean.valueOf(isSetName()).compareTo(other.isSetName());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(name, other.name);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetUnderlyingName()).compareTo(other.isSetUnderlyingName());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(underlyingName, other.underlyingName);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetExtraNamespace()).compareTo(other.isSetExtraNamespace());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(extraNamespace, other.extraNamespace);
    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 NAME:
          if (__field.type == TType.STRING) {
            this.name = iprot.readString();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case UNDERLYINGNAME:
          if (__field.type == TType.STRING) {
            this.underlyingName = iprot.readString();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case EXTRANAMESPACE:
          if (__field.type == TType.STRING) {
            this.extraNamespace = iprot.readString();
          } 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.name != null) {
      oprot.writeFieldBegin(NAME_FIELD_DESC);
      oprot.writeString(this.name);
      oprot.writeFieldEnd();
    }
    if (this.underlyingName != null) {
      oprot.writeFieldBegin(UNDERLYING_NAME_FIELD_DESC);
      oprot.writeString(this.underlyingName);
      oprot.writeFieldEnd();
    }
    if (this.extraNamespace != null) {
      oprot.writeFieldBegin(EXTRA_NAMESPACE_FIELD_DESC);
      oprot.writeString(this.extraNamespace);
      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("Wrapper");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("name");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getName() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getName(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("underlyingName");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getUnderlyingName() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getUnderlyingName(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("extraNamespace");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getExtraNamespace() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getExtraNamespace(), 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
  }

}

