/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */

package thrift.test;

import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.concurrent.Immutable;
import javax.annotation.Nullable;
import com.facebook.hyperthrift.HyperThriftBase;
import com.facebook.hyperthrift.reflect.HyperThriftType;

@Immutable
@HyperThriftType
public class XUnion extends HyperThriftBase {
  public static final String TYPE_NAME = "thrift.test.XUnion";

  @IntDef({
    Fields.first,
    Fields.second,
    Fields.third,
  })
  public @interface Fields {
    int first = 1;
    int second = 2;
    int third = 3;
  }

  public @Fields int getUnionFieldId() {
    return getUnionFieldIdInternal();
  }

  public Object getUnionFieldValue() {
    return getFieldValue(getUnionFieldIndex());
  }

  @Nullable
  public thrift.test.Xtruct first() {
    return getFieldValue(0);
  }

  @Nullable
  public thrift.test.Xtruct2 second() {
    return getFieldValue(1);
  }

  @Nullable
  public thrift.test.Xtruct3 third() {
    return getFieldValue(2);
  }



  public static class Builder extends HyperThriftBase.Builder {
    public Builder() {
      super(3);
    }

    public Builder(XUnion other) {
      super(other);
    }

    @Nullable
    public thrift.test.Xtruct first() {
      return getFieldValue(0);
    }

    public Builder XUnion( thrift.test.Xtruct value) {
      setFieldValue(0, value);
      mUnionFieldId = 1;
      return this;
    }

    @Nullable
    public thrift.test.Xtruct2 second() {
      return getFieldValue(1);
    }

    public Builder XUnion( thrift.test.Xtruct2 value) {
      setFieldValue(1, value);
      mUnionFieldId = 2;
      return this;
    }

    @Nullable
    public thrift.test.Xtruct3 third() {
      return getFieldValue(2);
    }

    public Builder XUnion( thrift.test.Xtruct3 value) {
      setFieldValue(2, value);
      mUnionFieldId = 3;
      return this;
    }

    public XUnion build() {
      Object[] fields = markBuilt();
      XUnion instance = new XUnion();
      instance.init(TYPE_NAME, fields);
      instance.assignUnionFieldId(mUnionFieldId);
      return instance;
    }
  }
}
