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

package test.fixtures.complex_struct;

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("optXcep")
public final class OptXcep 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("optXcep");
    private final String message;
    public static final int _MESSAGE = 1;
    private static final TField MESSAGE_FIELD_DESC = new TField("message", TType.STRING, (short)1);
    private final Integer errorCode;
    public static final int _ERRORCODE = 2;
    private static final TField ERROR_CODE_FIELD_DESC = new TField("errorCode", TType.I32, (short)2);

    static {
      NAMES_TO_IDS.put("message", 1);
      THRIFT_NAMES_TO_IDS.put("message", 1);
      FIELD_METADATA.put(1, MESSAGE_FIELD_DESC);
      NAMES_TO_IDS.put("errorCode", 2);
      THRIFT_NAMES_TO_IDS.put("errorCode", 2);
      FIELD_METADATA.put(2, ERROR_CODE_FIELD_DESC);
    }

    @ThriftConstructor
    public OptXcep(
        @com.facebook.swift.codec.ThriftField(value=1, name="message", requiredness=Requiredness.OPTIONAL) final String message,
        @com.facebook.swift.codec.ThriftField(value=2, name="errorCode", requiredness=Requiredness.OPTIONAL) final Integer errorCode
    ) {
        this.message = message;
        this.errorCode = errorCode;
    }
    
    @ThriftConstructor
    protected OptXcep() {
      this.message = null;
      this.errorCode = null;
    }
    
    public static class Builder {
        private String message = null;
        private Integer errorCode = null;
    
        @com.facebook.swift.codec.ThriftField(value=1, name="message", requiredness=Requiredness.OPTIONAL)
        public Builder setMessage(String message) {
            this.message = message;
            return this;
        }
    
        public String getMessage() { return message; }
    
            @com.facebook.swift.codec.ThriftField(value=2, name="errorCode", requiredness=Requiredness.OPTIONAL)
        public Builder setErrorCode(Integer errorCode) {
            this.errorCode = errorCode;
            return this;
        }
    
        public Integer getErrorCode() { return errorCode; }
    
        public Builder() { }
        public Builder(OptXcep other) {
            this.message = other.message;
            this.errorCode = other.errorCode;
        }
    
        @ThriftConstructor
        public OptXcep build() {
            OptXcep result = new OptXcep (
                this.message,
                this.errorCode
            );
            return result;
        }
    }
    
    
    @Nullable
    @com.facebook.swift.codec.ThriftField(value=1, name="message", requiredness=Requiredness.OPTIONAL)
    public String getMessage() { return message; }
        
    @Nullable
    @com.facebook.swift.codec.ThriftField(value=2, name="errorCode", requiredness=Requiredness.OPTIONAL)
    public Integer getErrorCode() { return errorCode; }
    
    
    public static com.facebook.thrift.payload.Reader<OptXcep> asReader() {
      return OptXcep::read0;
    }
    
    public static OptXcep read0(TProtocol oprot) throws TException {
      TField __field;
      oprot.readStructBegin(OptXcep.NAMES_TO_IDS, OptXcep.THRIFT_NAMES_TO_IDS, OptXcep.FIELD_METADATA);
      OptXcep.Builder builder = new OptXcep.Builder();
      while (true) {
        __field = oprot.readFieldBegin();
        if (__field.type == TType.STOP) { break; }
        switch (__field.id) {
        case _MESSAGE:
          if (__field.type == TType.STRING) {
            String message = oprot.readString();
            builder.setMessage(message);
          } else {
            TProtocolUtil.skip(oprot, __field.type);
          }
          break;
        case _ERRORCODE:
          if (__field.type == TType.I32) {
            Integer 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 (message != null) {
        oprot.writeFieldBegin(MESSAGE_FIELD_DESC);
        oprot.writeString(this.message);
        oprot.writeFieldEnd();
      }
      if (errorCode != null) {
        oprot.writeFieldBegin(ERROR_CODE_FIELD_DESC);
        oprot.writeI32(this.errorCode);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
    
    private static class _OptXcepLazy {
        private static final OptXcep _DEFAULT = new OptXcep.Builder().build();
    }
    
    public static OptXcep defaultInstance() {
        return  _OptXcepLazy._DEFAULT;
    }}
