/**
 * 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 Insanity : TBase
  {
    private Dictionary<global::ThriftTest.Numberz, long> _userMap;
    private List<global::ThriftTest.Xtruct> _xtructs;

    [DataMember(Order = 0)]
    public Dictionary<global::ThriftTest.Numberz, long> UserMap
    {
      get
      {
        return _userMap;
      }
      set
      {
        __isset.userMap = true;
        this._userMap = value;
      }
    }

    [DataMember(Order = 0)]
    public List<global::ThriftTest.Xtruct> Xtructs
    {
      get
      {
        return _xtructs;
      }
      set
      {
        __isset.xtructs = true;
        this._xtructs = value;
      }
    }


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

    #region XmlSerializer support

    public bool ShouldSerializeUserMap()
    {
      return __isset.userMap;
    }

    public bool ShouldSerializeXtructs()
    {
      return __isset.xtructs;
    }

    #endregion XmlSerializer support

    public Insanity()
    {
    }

    public Insanity DeepCopy()
    {
      var tmp10 = new Insanity();
      if((UserMap != null) && __isset.userMap)
      {
        tmp10.UserMap = this.UserMap.DeepCopy();
      }
      tmp10.__isset.userMap = this.__isset.userMap;
      if((Xtructs != null) && __isset.xtructs)
      {
        tmp10.Xtructs = this.Xtructs.DeepCopy();
      }
      tmp10.__isset.xtructs = this.__isset.xtructs;
      return tmp10;
    }

    public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
    {
      iprot.IncrementRecursionDepth();
      try
      {
        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.Map)
              {
                {
                  TMap _map11 = await iprot.ReadMapBeginAsync(cancellationToken);
                  UserMap = new Dictionary<global::ThriftTest.Numberz, long>(_map11.Count);
                  for(int _i12 = 0; _i12 < _map11.Count; ++_i12)
                  {
                    global::ThriftTest.Numberz _key13;
                    long _val14;
                    _key13 = (global::ThriftTest.Numberz)await iprot.ReadI32Async(cancellationToken);
                    _val14 = await iprot.ReadI64Async(cancellationToken);
                    UserMap[_key13] = _val14;
                  }
                  await iprot.ReadMapEndAsync(cancellationToken);
                }
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 2:
              if (field.Type == TType.List)
              {
                {
                  TList _list15 = await iprot.ReadListBeginAsync(cancellationToken);
                  Xtructs = new List<global::ThriftTest.Xtruct>(_list15.Count);
                  for(int _i16 = 0; _i16 < _list15.Count; ++_i16)
                  {
                    global::ThriftTest.Xtruct _elem17;
                    _elem17 = new global::ThriftTest.Xtruct();
                    await _elem17.ReadAsync(iprot, cancellationToken);
                    Xtructs.Add(_elem17);
                  }
                  await iprot.ReadListEndAsync(cancellationToken);
                }
              }
              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);
      }
      finally
      {
        iprot.DecrementRecursionDepth();
      }
    }

    public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
    {
      oprot.IncrementRecursionDepth();
      try
      {
        var struc = new TStruct("Insanity");
        await oprot.WriteStructBeginAsync(struc, cancellationToken);
        var field = new TField();
        if((UserMap != null) && __isset.userMap)
        {
          field.Name = "userMap";
          field.Type = TType.Map;
          field.ID = 1;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          {
            await oprot.WriteMapBeginAsync(new TMap(TType.I32, TType.I64, UserMap.Count), cancellationToken);
            foreach (global::ThriftTest.Numberz _iter18 in UserMap.Keys)
            {
              await oprot.WriteI32Async((int)_iter18, cancellationToken);
              await oprot.WriteI64Async(UserMap[_iter18], cancellationToken);
            }
            await oprot.WriteMapEndAsync(cancellationToken);
          }
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Xtructs != null) && __isset.xtructs)
        {
          field.Name = "xtructs";
          field.Type = TType.List;
          field.ID = 2;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          {
            await oprot.WriteListBeginAsync(new TList(TType.Struct, Xtructs.Count), cancellationToken);
            foreach (global::ThriftTest.Xtruct _iter19 in Xtructs)
            {
              await _iter19.WriteAsync(oprot, cancellationToken);
            }
            await oprot.WriteListEndAsync(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 Insanity other)) return false;
      if (ReferenceEquals(this, other)) return true;
      return ((__isset.userMap == other.__isset.userMap) && ((!__isset.userMap) || (TCollections.Equals(UserMap, other.UserMap))))
        && ((__isset.xtructs == other.__isset.xtructs) && ((!__isset.xtructs) || (TCollections.Equals(Xtructs, other.Xtructs))));
    }

    public override int GetHashCode() {
      int hashcode = 157;
      unchecked {
        if((UserMap != null) && __isset.userMap)
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(UserMap);
        }
        if((Xtructs != null) && __isset.xtructs)
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Xtructs);
        }
      }
      return hashcode;
    }

    public override string ToString()
    {
      var sb = new StringBuilder("Insanity(");
      int tmp20 = 0;
      if((UserMap != null) && __isset.userMap)
      {
        if(0 < tmp20++) { sb.Append(", "); }
        sb.Append("UserMap: ");
        UserMap.ToString(sb);
      }
      if((Xtructs != null) && __isset.xtructs)
      {
        if(0 < tmp20++) { sb.Append(", "); }
        sb.Append("Xtructs: ");
        Xtructs.ToString(sb);
      }
      sb.Append(')');
      return sb.ToString();
    }
  }

}
