/**
 * Autogenerated by Thrift Compiler (0.14.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Thrift;
using Thrift.Collections;
using System.ServiceModel;
using System.Runtime.Serialization;

using Thrift.Protocol;
using Thrift.Protocol.Entities;
using Thrift.Protocol.Utilities;
using Thrift.Transport;
using Thrift.Transport.Client;
using Thrift.Transport.Server;
using Thrift.Processor;


#pragma warning disable IDE0079  // remove unnecessary pragmas
#pragma warning disable IDE1006  // parts of the code use IDL spelling

namespace ThriftTest
{

[DataContract(Namespace="")]
public partial class StructB : TBase
{
  private global::ThriftTest.StructA _aa;

  [DataMember(Order = 0)]
  public global::ThriftTest.StructA Aa
  {
    get
    {
      return _aa;
    }
    set
    {
      __isset.aa = true;
      this._aa = value;
    }
  }

  [DataMember(Order = 0)]
  public global::ThriftTest.StructA Ab { get; set; }


  [DataMember(Order = 1)]
  public Isset __isset;
  [DataContract]
  public struct Isset
  {
    [DataMember]
    public bool aa;
  }

  #region XmlSerializer support

  public bool ShouldSerializeAa()
  {
    return __isset.aa;
  }

  #endregion XmlSerializer support

  public StructB()
  {
  }

  public StructB(global::ThriftTest.StructA ab) : this()
  {
    this.Ab = ab;
  }

  public StructB DeepCopy()
  {
    var tmp197 = new StructB();
    if((Aa != null) && __isset.aa)
    {
      tmp197.Aa = (global::ThriftTest.StructA)this.Aa.DeepCopy();
    }
    tmp197.__isset.aa = this.__isset.aa;
    if((Ab != null))
    {
      tmp197.Ab = (global::ThriftTest.StructA)this.Ab.DeepCopy();
    }
    return tmp197;
  }

  public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
  {
    iprot.IncrementRecursionDepth();
    try
    {
      bool isset_ab = false;
      TField field;
      await iprot.ReadStructBeginAsync(cancellationToken);
      while (true)
      {
        field = await iprot.ReadFieldBeginAsync(cancellationToken);
        if (field.Type == TType.Stop)
        {
          break;
        }

        switch (field.ID)
        {
          case 1:
            if (field.Type == TType.Struct)
            {
              Aa = new global::ThriftTest.StructA();
              await Aa.ReadAsync(iprot, cancellationToken);
            }
            else
            {
              await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
            }
            break;
          case 2:
            if (field.Type == TType.Struct)
            {
              Ab = new global::ThriftTest.StructA();
              await Ab.ReadAsync(iprot, cancellationToken);
              isset_ab = true;
            }
            else
            {
              await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
            }
            break;
          default: 
            await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
            break;
        }

        await iprot.ReadFieldEndAsync(cancellationToken);
      }

      await iprot.ReadStructEndAsync(cancellationToken);
      if (!isset_ab)
      {
        throw new TProtocolException(TProtocolException.INVALID_DATA);
      }
    }
    finally
    {
      iprot.DecrementRecursionDepth();
    }
  }

  public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
  {
    oprot.IncrementRecursionDepth();
    try
    {
      var struc = new TStruct("StructB");
      await oprot.WriteStructBeginAsync(struc, cancellationToken);
      var field = new TField();
      if((Aa != null) && __isset.aa)
      {
        field.Name = "aa";
        field.Type = TType.Struct;
        field.ID = 1;
        await oprot.WriteFieldBeginAsync(field, cancellationToken);
        await Aa.WriteAsync(oprot, cancellationToken);
        await oprot.WriteFieldEndAsync(cancellationToken);
      }
      if((Ab != null))
      {
        field.Name = "ab";
        field.Type = TType.Struct;
        field.ID = 2;
        await oprot.WriteFieldBeginAsync(field, cancellationToken);
        await Ab.WriteAsync(oprot, cancellationToken);
        await oprot.WriteFieldEndAsync(cancellationToken);
      }
      await oprot.WriteFieldStopAsync(cancellationToken);
      await oprot.WriteStructEndAsync(cancellationToken);
    }
    finally
    {
      oprot.DecrementRecursionDepth();
    }
  }

  public override bool Equals(object that)
  {
    if (!(that is StructB other)) return false;
    if (ReferenceEquals(this, other)) return true;
    return ((__isset.aa == other.__isset.aa) && ((!__isset.aa) || (System.Object.Equals(Aa, other.Aa))))
      && System.Object.Equals(Ab, other.Ab);
  }

  public override int GetHashCode() {
    int hashcode = 157;
    unchecked {
      if((Aa != null) && __isset.aa)
      {
        hashcode = (hashcode * 397) + Aa.GetHashCode();
      }
      if((Ab != null))
      {
        hashcode = (hashcode * 397) + Ab.GetHashCode();
      }
    }
    return hashcode;
  }

  public override string ToString()
  {
    var sb = new StringBuilder("StructB(");
    int tmp198 = 0;
    if((Aa != null) && __isset.aa)
    {
      if(0 < tmp198++) { sb.Append(", "); }
      sb.Append("Aa: ");
      Aa.ToString(sb);
    }
    if((Ab != null))
    {
      if(0 < tmp198) { sb.Append(", "); }
      sb.Append("Ab: ");
      Ab.ToString(sb);
    }
    sb.Append(')');
    return sb.ToString();
  }
}

}
