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

package test.fixtures.exceptions;

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

@SwiftGenerated
@com.facebook.swift.codec.ThriftStruct("ExceptionWithStructuredAnnotation")
public final class ExceptionWithStructuredAnnotation extends org.apache.thrift.TBaseException implements com.facebook.thrift.payload.ThriftSerializable {
    private static final long serialVersionUID = 1L;

    
    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("ExceptionWithStructuredAnnotation");
    private final String messageField;
    public static final int _MESSAGE_FIELD = 1;
    private static final TField MESSAGE_FIELD_FIELD_DESC = new TField("messageField", TType.STRING, (short)1);
    private final int errorCode;
    public static final int _ERROR_CODE = 2;
    private static final TField ERROR_CODE_FIELD_DESC = new TField("errorCode", TType.I32, (short)2);

    static {
      NAMES_TO_IDS.put("messageField", 1);
      THRIFT_NAMES_TO_IDS.put("message_field", 1);
      FIELD_METADATA.put(1, MESSAGE_FIELD_FIELD_DESC);
      NAMES_TO_IDS.put("errorCode", 2);
      THRIFT_NAMES_TO_IDS.put("error_code", 2);
      FIELD_METADATA.put(2, ERROR_CODE_FIELD_DESC);
    }

    @ThriftConstructor
    public ExceptionWithStructuredAnnotation(
        @com.facebook.swift.codec.ThriftField(value=1, name="message_field", requiredness=Requiredness.NONE) final String messageField,
        @com.facebook.swift.codec.ThriftField(value=2, name="error_code", requiredness=Requiredness.NONE) final int errorCode
    ) {
        this.messageField = messageField;
        this.errorCode = errorCode;
    }
    
    @ThriftConstructor
    protected ExceptionWithStructuredAnnotation() {
      this.messageField = null;
      this.errorCode = 0;
    }
    
    public static class Builder {
        private String messageField = null;
        private int errorCode = 0;
    
        @com.facebook.swift.codec.ThriftField(value=1, name="message_field", requiredness=Requiredness.NONE)
        public Builder setMessageField(String messageField) {
            this.messageField = messageField;
            return this;
        }
    
        public String getMessageField() { return messageField; }
    
            @com.facebook.swift.codec.ThriftField(value=2, name="error_code", requiredness=Requiredness.NONE)
        public Builder setErrorCode(int errorCode) {
            this.errorCode = errorCode;
            return this;
        }
    
        public int getErrorCode() { return errorCode; }
    
        public Builder() { }
        public Builder(ExceptionWithStructuredAnnotation other) {
            this.messageField = other.messageField;
            this.errorCode = other.errorCode;
        }
    
        @ThriftConstructor
        public ExceptionWithStructuredAnnotation build() {
            ExceptionWithStructuredAnnotation result = new ExceptionWithStructuredAnnotation (
                this.messageField,
                this.errorCode
            );
            return result;
        }
    }
    
    
    @Nullable
    @com.facebook.swift.codec.ThriftField(value=1, name="message_field", requiredness=Requiredness.NONE)
    public String getMessageField() { return messageField; }
        
    
    @com.facebook.swift.codec.ThriftField(value=2, name="error_code", requiredness=Requiredness.NONE)
    public int getErrorCode() { return errorCode; }
    
    
    public static com.facebook.thrift.payload.Reader<ExceptionWithStructuredAnnotation> asReader() {
      return ExceptionWithStructuredAnnotation::read0;
    }
    
    public static ExceptionWithStructuredAnnotation read0(TProtocol oprot) throws TException {
      TField __field;
      oprot.readStructBegin(ExceptionWithStructuredAnnotation.NAMES_TO_IDS, ExceptionWithStructuredAnnotation.THRIFT_NAMES_TO_IDS, ExceptionWithStructuredAnnotation.FIELD_METADATA);
      ExceptionWithStructuredAnnotation.Builder builder = new ExceptionWithStructuredAnnotation.Builder();
      while (true) {
        __field = oprot.readFieldBegin();
        if (__field.type == TType.STOP) { break; }
        switch (__field.id) {
        case _MESSAGE_FIELD:
          if (__field.type == TType.STRING) {
            String messageField = oprot.readString();
            builder.setMessageField(messageField);
          } else {
            TProtocolUtil.skip(oprot, __field.type);
          }
          break;
        case _ERROR_CODE:
          if (__field.type == TType.I32) {
            int errorCode = oprot.readI32();
            builder.setErrorCode(errorCode);
          } 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 (messageField != null) {
        oprot.writeFieldBegin(MESSAGE_FIELD_FIELD_DESC);
        oprot.writeString(this.messageField);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldBegin(ERROR_CODE_FIELD_DESC);
      oprot.writeI32(this.errorCode);
      oprot.writeFieldEnd();
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
    
    private static class _ExceptionWithStructuredAnnotationLazy {
        private static final ExceptionWithStructuredAnnotation _DEFAULT = new ExceptionWithStructuredAnnotation.Builder().build();
    }
    
    public static ExceptionWithStructuredAnnotation defaultInstance() {
        return  _ExceptionWithStructuredAnnotationLazy._DEFAULT;
    }}
