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

package test.fixtures.refs;

import com.facebook.swift.codec.*;
import com.facebook.swift.codec.ThriftField.Requiredness;
import com.facebook.swift.codec.ThriftField.Recursiveness;
import com.google.common.collect.*;
import java.util.*;
import javax.annotation.Nullable;
import org.apache.thrift.*;
import org.apache.thrift.transport.*;
import org.apache.thrift.protocol.*;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.MoreObjects.ToStringHelper;

@SwiftGenerated
@com.facebook.swift.codec.ThriftStruct(value="StructWithRefTypeUnique", builder=StructWithRefTypeUnique.Builder.class)
public final class StructWithRefTypeUnique implements com.facebook.thrift.payload.ThriftSerializable {
    @ThriftConstructor
    public StructWithRefTypeUnique(
        @com.facebook.swift.codec.ThriftField(value=1, name="def_field", requiredness=Requiredness.NONE) final test.fixtures.refs.Empty defField,
        @com.facebook.swift.codec.ThriftField(value=2, name="opt_field", requiredness=Requiredness.OPTIONAL) final test.fixtures.refs.Empty optField,
        @com.facebook.swift.codec.ThriftField(value=3, name="req_field", requiredness=Requiredness.REQUIRED) final test.fixtures.refs.Empty reqField
    ) {
        this.defField = defField;
        this.optField = optField;
        this.reqField = reqField;
    }
    
    @ThriftConstructor
    protected StructWithRefTypeUnique() {
      this.defField = null;
      this.optField = null;
      this.reqField = null;
    }
    
    public static Builder builder() {
      return new Builder();
    }

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

    public static class Builder {
        private test.fixtures.refs.Empty defField = null;
        private test.fixtures.refs.Empty optField = null;
        private test.fixtures.refs.Empty reqField = null;
    
        @com.facebook.swift.codec.ThriftField(value=1, name="def_field", requiredness=Requiredness.NONE)
        public Builder setDefField(test.fixtures.refs.Empty defField) {
            this.defField = defField;
            return this;
        }
    
        public test.fixtures.refs.Empty getDefField() { return defField; }
    
            @com.facebook.swift.codec.ThriftField(value=2, name="opt_field", requiredness=Requiredness.OPTIONAL)
        public Builder setOptField(test.fixtures.refs.Empty optField) {
            this.optField = optField;
            return this;
        }
    
        public test.fixtures.refs.Empty getOptField() { return optField; }
    
            @com.facebook.swift.codec.ThriftField(value=3, name="req_field", requiredness=Requiredness.REQUIRED)
        public Builder setReqField(test.fixtures.refs.Empty reqField) {
            this.reqField = reqField;
            return this;
        }
    
        public test.fixtures.refs.Empty getReqField() { return reqField; }
    
        public Builder() { }
        public Builder(StructWithRefTypeUnique other) {
            this.defField = other.defField;
            this.optField = other.optField;
            this.reqField = other.reqField;
        }
    
        @ThriftConstructor
        public StructWithRefTypeUnique build() {
            StructWithRefTypeUnique result = new StructWithRefTypeUnique (
                this.defField,
                this.optField,
                this.reqField
            );
            return result;
        }
    }
        
    public static final Map<String, Integer> NAMES_TO_IDS = new HashMap<>();
    public static final Map<String, Integer> THRIFT_NAMES_TO_IDS = new HashMap<>();
    public static final Map<Integer, TField> FIELD_METADATA = new HashMap<>();
    private static final TStruct STRUCT_DESC = new TStruct("StructWithRefTypeUnique");
    private final test.fixtures.refs.Empty defField;
    public static final int _DEF_FIELD = 1;
    private static final TField DEF_FIELD_FIELD_DESC = new TField("def_field", TType.STRUCT, (short)1);
        private final test.fixtures.refs.Empty optField;
    public static final int _OPT_FIELD = 2;
    private static final TField OPT_FIELD_FIELD_DESC = new TField("opt_field", TType.STRUCT, (short)2);
        private final test.fixtures.refs.Empty reqField;
    public static final int _REQ_FIELD = 3;
    private static final TField REQ_FIELD_FIELD_DESC = new TField("req_field", TType.STRUCT, (short)3);
    static {
      NAMES_TO_IDS.put("defField", 1);
      THRIFT_NAMES_TO_IDS.put("def_field", 1);
      FIELD_METADATA.put(1, DEF_FIELD_FIELD_DESC);
      NAMES_TO_IDS.put("optField", 2);
      THRIFT_NAMES_TO_IDS.put("opt_field", 2);
      FIELD_METADATA.put(2, OPT_FIELD_FIELD_DESC);
      NAMES_TO_IDS.put("reqField", 3);
      THRIFT_NAMES_TO_IDS.put("req_field", 3);
      FIELD_METADATA.put(3, REQ_FIELD_FIELD_DESC);
    }
    
    @Nullable
    @com.facebook.swift.codec.ThriftField(value=1, name="def_field", requiredness=Requiredness.NONE)
    public test.fixtures.refs.Empty getDefField() { return defField; }
    
    
    @Nullable
    @com.facebook.swift.codec.ThriftField(value=2, name="opt_field", requiredness=Requiredness.OPTIONAL)
    public test.fixtures.refs.Empty getOptField() { return optField; }
    
    
    
    @com.facebook.swift.codec.ThriftField(value=3, name="req_field", requiredness=Requiredness.REQUIRED)
    public test.fixtures.refs.Empty getReqField() { return reqField; }
    
    @java.lang.Override
    public String toString() {
        ToStringHelper helper = toStringHelper(this);
        helper.add("defField", defField);
        helper.add("optField", optField);
        helper.add("reqField", reqField);
        return helper.toString();
    }
    
    @java.lang.Override
    public boolean equals(java.lang.Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
    
        StructWithRefTypeUnique other = (StructWithRefTypeUnique)o;
    
        return
            Objects.equals(defField, other.defField) &&
            Objects.equals(optField, other.optField) &&
            Objects.equals(reqField, other.reqField) &&
            true;
    }
    
    @java.lang.Override
    public int hashCode() {
        return Arrays.deepHashCode(new java.lang.Object[] {
            defField,
            optField,
            reqField
        });
    }
    
    
    public static com.facebook.thrift.payload.Reader<StructWithRefTypeUnique> asReader() {
      return StructWithRefTypeUnique::read0;
    }
    
    public static StructWithRefTypeUnique read0(TProtocol oprot) throws TException {
      TField __field;
      oprot.readStructBegin(StructWithRefTypeUnique.NAMES_TO_IDS, StructWithRefTypeUnique.THRIFT_NAMES_TO_IDS, StructWithRefTypeUnique.FIELD_METADATA);
      StructWithRefTypeUnique.Builder builder = new StructWithRefTypeUnique.Builder();
      while (true) {
        __field = oprot.readFieldBegin();
        if (__field.type == TType.STOP) { break; }
        switch (__field.id) {
        case _DEF_FIELD:
          if (__field.type == TType.STRUCT) {
            test.fixtures.refs.Empty defField = test.fixtures.refs.Empty.read0(oprot);
            builder.setDefField(defField);
          } else {
            TProtocolUtil.skip(oprot, __field.type);
          }
          break;
        case _OPT_FIELD:
          if (__field.type == TType.STRUCT) {
            test.fixtures.refs.Empty optField = test.fixtures.refs.Empty.read0(oprot);
            builder.setOptField(optField);
          } else {
            TProtocolUtil.skip(oprot, __field.type);
          }
          break;
        case _REQ_FIELD:
          if (__field.type == TType.STRUCT) {
            test.fixtures.refs.Empty reqField = test.fixtures.refs.Empty.read0(oprot);
            builder.setReqField(reqField);
          } else {
            TProtocolUtil.skip(oprot, __field.type);
          }
          break;
        default:
          TProtocolUtil.skip(oprot, __field.type);
          break;
        }
        oprot.readFieldEnd();
      }
      oprot.readStructEnd();
      return builder.build();
    }
    
    public void write0(TProtocol oprot) throws TException {
      oprot.writeStructBegin(STRUCT_DESC);
      if (defField != null) {
        oprot.writeFieldBegin(DEF_FIELD_FIELD_DESC);
        this.defField.write0(oprot);
        oprot.writeFieldEnd();
      }
      if (optField != null) {
        oprot.writeFieldBegin(OPT_FIELD_FIELD_DESC);
        this.optField.write0(oprot);
        oprot.writeFieldEnd();
      }
      if (reqField != null) {
        oprot.writeFieldBegin(REQ_FIELD_FIELD_DESC);
        this.reqField.write0(oprot);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
    
    private static class _StructWithRefTypeUniqueLazy {
        private static final StructWithRefTypeUnique _DEFAULT = new StructWithRefTypeUnique.Builder().build();
    }
    
    public static StructWithRefTypeUnique defaultInstance() {
        return  _StructWithRefTypeUniqueLazy._DEFAULT;
    }
}
