/**
 * 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 Apache.Cassandra.Test
{

  [DataContract(Namespace="")]
  public partial class ColumnDef : TBase
  {
    private global::Apache.Cassandra.Test.IndexType _index_type;
    private string _index_name;
    private Dictionary<string, string> _index_options;

    [DataMember(Order = 0)]
    public byte[] Name { get; set; }

    [DataMember(Order = 0)]
    public string Validation_class { get; set; }

    /// <summary>
    /// 
    /// <seealso cref="global::Apache.Cassandra.Test.IndexType"/>
    /// </summary>
    [DataMember(Order = 0)]
    public global::Apache.Cassandra.Test.IndexType Index_type
    {
      get
      {
        return _index_type;
      }
      set
      {
        __isset.index_type = true;
        this._index_type = value;
      }
    }

    [DataMember(Order = 0)]
    public string Index_name
    {
      get
      {
        return _index_name;
      }
      set
      {
        __isset.index_name = true;
        this._index_name = value;
      }
    }

    [DataMember(Order = 0)]
    public Dictionary<string, string> Index_options
    {
      get
      {
        return _index_options;
      }
      set
      {
        __isset.index_options = true;
        this._index_options = value;
      }
    }


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

    #region XmlSerializer support

    public bool ShouldSerializeIndex_type()
    {
      return __isset.index_type;
    }

    public bool ShouldSerializeIndex_name()
    {
      return __isset.index_name;
    }

    public bool ShouldSerializeIndex_options()
    {
      return __isset.index_options;
    }

    #endregion XmlSerializer support

    public ColumnDef()
    {
    }

    public ColumnDef(byte[] name, string validation_class) : this()
    {
      this.Name = name;
      this.Validation_class = validation_class;
    }

    public ColumnDef DeepCopy()
    {
      var tmp89 = new ColumnDef();
      if((Name != null))
      {
        tmp89.Name = this.Name.ToArray();
      }
      if((Validation_class != null))
      {
        tmp89.Validation_class = this.Validation_class;
      }
      if(__isset.index_type)
      {
        tmp89.Index_type = this.Index_type;
      }
      tmp89.__isset.index_type = this.__isset.index_type;
      if((Index_name != null) && __isset.index_name)
      {
        tmp89.Index_name = this.Index_name;
      }
      tmp89.__isset.index_name = this.__isset.index_name;
      if((Index_options != null) && __isset.index_options)
      {
        tmp89.Index_options = this.Index_options.DeepCopy();
      }
      tmp89.__isset.index_options = this.__isset.index_options;
      return tmp89;
    }

    public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
    {
      iprot.IncrementRecursionDepth();
      try
      {
        bool isset_name = false;
        bool isset_validation_class = 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.String)
              {
                Name = await iprot.ReadBinaryAsync(cancellationToken);
                isset_name = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 2:
              if (field.Type == TType.String)
              {
                Validation_class = await iprot.ReadStringAsync(cancellationToken);
                isset_validation_class = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 3:
              if (field.Type == TType.I32)
              {
                Index_type = (global::Apache.Cassandra.Test.IndexType)await iprot.ReadI32Async(cancellationToken);
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 4:
              if (field.Type == TType.String)
              {
                Index_name = await iprot.ReadStringAsync(cancellationToken);
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 5:
              if (field.Type == TType.Map)
              {
                {
                  TMap _map90 = await iprot.ReadMapBeginAsync(cancellationToken);
                  Index_options = new Dictionary<string, string>(_map90.Count);
                  for(int _i91 = 0; _i91 < _map90.Count; ++_i91)
                  {
                    string _key92;
                    string _val93;
                    _key92 = await iprot.ReadStringAsync(cancellationToken);
                    _val93 = await iprot.ReadStringAsync(cancellationToken);
                    Index_options[_key92] = _val93;
                  }
                  await iprot.ReadMapEndAsync(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);
        if (!isset_name)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_validation_class)
        {
          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("ColumnDef");
        await oprot.WriteStructBeginAsync(struc, cancellationToken);
        var field = new TField();
        if((Name != null))
        {
          field.Name = "name";
          field.Type = TType.String;
          field.ID = 1;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteBinaryAsync(Name, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Validation_class != null))
        {
          field.Name = "validation_class";
          field.Type = TType.String;
          field.ID = 2;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteStringAsync(Validation_class, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if(__isset.index_type)
        {
          field.Name = "index_type";
          field.Type = TType.I32;
          field.ID = 3;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteI32Async((int)Index_type, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Index_name != null) && __isset.index_name)
        {
          field.Name = "index_name";
          field.Type = TType.String;
          field.ID = 4;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteStringAsync(Index_name, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Index_options != null) && __isset.index_options)
        {
          field.Name = "index_options";
          field.Type = TType.Map;
          field.ID = 5;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          {
            await oprot.WriteMapBeginAsync(new TMap(TType.String, TType.String, Index_options.Count), cancellationToken);
            foreach (string _iter94 in Index_options.Keys)
            {
              await oprot.WriteStringAsync(_iter94, cancellationToken);
              await oprot.WriteStringAsync(Index_options[_iter94], cancellationToken);
            }
            await oprot.WriteMapEndAsync(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 ColumnDef other)) return false;
      if (ReferenceEquals(this, other)) return true;
      return TCollections.Equals(Name, other.Name)
        && System.Object.Equals(Validation_class, other.Validation_class)
        && ((__isset.index_type == other.__isset.index_type) && ((!__isset.index_type) || (System.Object.Equals(Index_type, other.Index_type))))
        && ((__isset.index_name == other.__isset.index_name) && ((!__isset.index_name) || (System.Object.Equals(Index_name, other.Index_name))))
        && ((__isset.index_options == other.__isset.index_options) && ((!__isset.index_options) || (TCollections.Equals(Index_options, other.Index_options))));
    }

    public override int GetHashCode() {
      int hashcode = 157;
      unchecked {
        if((Name != null))
        {
          hashcode = (hashcode * 397) + Name.GetHashCode();
        }
        if((Validation_class != null))
        {
          hashcode = (hashcode * 397) + Validation_class.GetHashCode();
        }
        if(__isset.index_type)
        {
          hashcode = (hashcode * 397) + Index_type.GetHashCode();
        }
        if((Index_name != null) && __isset.index_name)
        {
          hashcode = (hashcode * 397) + Index_name.GetHashCode();
        }
        if((Index_options != null) && __isset.index_options)
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Index_options);
        }
      }
      return hashcode;
    }

    public override string ToString()
    {
      var sb = new StringBuilder("ColumnDef(");
      if((Name != null))
      {
        sb.Append(", Name: ");
        Name.ToString(sb);
      }
      if((Validation_class != null))
      {
        sb.Append(", Validation_class: ");
        Validation_class.ToString(sb);
      }
      if(__isset.index_type)
      {
        sb.Append(", Index_type: ");
        Index_type.ToString(sb);
      }
      if((Index_name != null) && __isset.index_name)
      {
        sb.Append(", Index_name: ");
        Index_name.ToString(sb);
      }
      if((Index_options != null) && __isset.index_options)
      {
        sb.Append(", Index_options: ");
        Index_options.ToString(sb);
      }
      sb.Append(')');
      return sb.ToString();
    }
  }

}
