/**
 * 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 KsDef : TBase
  {
    private Dictionary<string, string> _strategy_options;
    private int _replication_factor;
    private bool _durable_writes;

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

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

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

    /// <summary>
    /// @deprecated
    /// </summary>
    [DataMember(Order = 0)]
    public int Replication_factor
    {
      get
      {
        return _replication_factor;
      }
      set
      {
        __isset.replication_factor = true;
        this._replication_factor = value;
      }
    }

    [DataMember(Order = 0)]
    public List<global::Apache.Cassandra.Test.CfDef> Cf_defs { get; set; }

    [DataMember(Order = 0)]
    public bool Durable_writes
    {
      get
      {
        return _durable_writes;
      }
      set
      {
        __isset.durable_writes = true;
        this._durable_writes = value;
      }
    }


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

    #region XmlSerializer support

    public bool ShouldSerializeStrategy_options()
    {
      return __isset.strategy_options;
    }

    public bool ShouldSerializeReplication_factor()
    {
      return __isset.replication_factor;
    }

    public bool ShouldSerializeDurable_writes()
    {
      return __isset.durable_writes;
    }

    #endregion XmlSerializer support

    public KsDef()
    {
      this._durable_writes = true;
      this.__isset.durable_writes = true;
    }

    public KsDef(string name, string strategy_class, List<global::Apache.Cassandra.Test.CfDef> cf_defs) : this()
    {
      this.Name = name;
      this.Strategy_class = strategy_class;
      this.Cf_defs = cf_defs;
    }

    public KsDef DeepCopy()
    {
      var tmp112 = new KsDef();
      if((Name != null))
      {
        tmp112.Name = this.Name;
      }
      if((Strategy_class != null))
      {
        tmp112.Strategy_class = this.Strategy_class;
      }
      if((Strategy_options != null) && __isset.strategy_options)
      {
        tmp112.Strategy_options = this.Strategy_options.DeepCopy();
      }
      tmp112.__isset.strategy_options = this.__isset.strategy_options;
      if(__isset.replication_factor)
      {
        tmp112.Replication_factor = this.Replication_factor;
      }
      tmp112.__isset.replication_factor = this.__isset.replication_factor;
      if((Cf_defs != null))
      {
        tmp112.Cf_defs = this.Cf_defs.DeepCopy();
      }
      if(__isset.durable_writes)
      {
        tmp112.Durable_writes = this.Durable_writes;
      }
      tmp112.__isset.durable_writes = this.__isset.durable_writes;
      return tmp112;
    }

    public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
    {
      iprot.IncrementRecursionDepth();
      try
      {
        bool isset_name = false;
        bool isset_strategy_class = false;
        bool isset_cf_defs = 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.ReadStringAsync(cancellationToken);
                isset_name = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 2:
              if (field.Type == TType.String)
              {
                Strategy_class = await iprot.ReadStringAsync(cancellationToken);
                isset_strategy_class = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 3:
              if (field.Type == TType.Map)
              {
                {
                  TMap _map113 = await iprot.ReadMapBeginAsync(cancellationToken);
                  Strategy_options = new Dictionary<string, string>(_map113.Count);
                  for(int _i114 = 0; _i114 < _map113.Count; ++_i114)
                  {
                    string _key115;
                    string _val116;
                    _key115 = await iprot.ReadStringAsync(cancellationToken);
                    _val116 = await iprot.ReadStringAsync(cancellationToken);
                    Strategy_options[_key115] = _val116;
                  }
                  await iprot.ReadMapEndAsync(cancellationToken);
                }
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 4:
              if (field.Type == TType.I32)
              {
                Replication_factor = await iprot.ReadI32Async(cancellationToken);
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 5:
              if (field.Type == TType.List)
              {
                {
                  TList _list117 = await iprot.ReadListBeginAsync(cancellationToken);
                  Cf_defs = new List<global::Apache.Cassandra.Test.CfDef>(_list117.Count);
                  for(int _i118 = 0; _i118 < _list117.Count; ++_i118)
                  {
                    global::Apache.Cassandra.Test.CfDef _elem119;
                    _elem119 = new global::Apache.Cassandra.Test.CfDef();
                    await _elem119.ReadAsync(iprot, cancellationToken);
                    Cf_defs.Add(_elem119);
                  }
                  await iprot.ReadListEndAsync(cancellationToken);
                }
                isset_cf_defs = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 6:
              if (field.Type == TType.Bool)
              {
                Durable_writes = await iprot.ReadBoolAsync(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_strategy_class)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_cf_defs)
        {
          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("KsDef");
        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.WriteStringAsync(Name, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Strategy_class != null))
        {
          field.Name = "strategy_class";
          field.Type = TType.String;
          field.ID = 2;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteStringAsync(Strategy_class, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Strategy_options != null) && __isset.strategy_options)
        {
          field.Name = "strategy_options";
          field.Type = TType.Map;
          field.ID = 3;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          {
            await oprot.WriteMapBeginAsync(new TMap(TType.String, TType.String, Strategy_options.Count), cancellationToken);
            foreach (string _iter120 in Strategy_options.Keys)
            {
              await oprot.WriteStringAsync(_iter120, cancellationToken);
              await oprot.WriteStringAsync(Strategy_options[_iter120], cancellationToken);
            }
            await oprot.WriteMapEndAsync(cancellationToken);
          }
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if(__isset.replication_factor)
        {
          field.Name = "replication_factor";
          field.Type = TType.I32;
          field.ID = 4;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteI32Async(Replication_factor, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Cf_defs != null))
        {
          field.Name = "cf_defs";
          field.Type = TType.List;
          field.ID = 5;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          {
            await oprot.WriteListBeginAsync(new TList(TType.Struct, Cf_defs.Count), cancellationToken);
            foreach (global::Apache.Cassandra.Test.CfDef _iter121 in Cf_defs)
            {
              await _iter121.WriteAsync(oprot, cancellationToken);
            }
            await oprot.WriteListEndAsync(cancellationToken);
          }
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if(__isset.durable_writes)
        {
          field.Name = "durable_writes";
          field.Type = TType.Bool;
          field.ID = 6;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteBoolAsync(Durable_writes, 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 KsDef other)) return false;
      if (ReferenceEquals(this, other)) return true;
      return System.Object.Equals(Name, other.Name)
        && System.Object.Equals(Strategy_class, other.Strategy_class)
        && ((__isset.strategy_options == other.__isset.strategy_options) && ((!__isset.strategy_options) || (TCollections.Equals(Strategy_options, other.Strategy_options))))
        && ((__isset.replication_factor == other.__isset.replication_factor) && ((!__isset.replication_factor) || (System.Object.Equals(Replication_factor, other.Replication_factor))))
        && TCollections.Equals(Cf_defs, other.Cf_defs)
        && ((__isset.durable_writes == other.__isset.durable_writes) && ((!__isset.durable_writes) || (System.Object.Equals(Durable_writes, other.Durable_writes))));
    }

    public override int GetHashCode() {
      int hashcode = 157;
      unchecked {
        if((Name != null))
        {
          hashcode = (hashcode * 397) + Name.GetHashCode();
        }
        if((Strategy_class != null))
        {
          hashcode = (hashcode * 397) + Strategy_class.GetHashCode();
        }
        if((Strategy_options != null) && __isset.strategy_options)
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Strategy_options);
        }
        if(__isset.replication_factor)
        {
          hashcode = (hashcode * 397) + Replication_factor.GetHashCode();
        }
        if((Cf_defs != null))
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Cf_defs);
        }
        if(__isset.durable_writes)
        {
          hashcode = (hashcode * 397) + Durable_writes.GetHashCode();
        }
      }
      return hashcode;
    }

    public override string ToString()
    {
      var sb = new StringBuilder("KsDef(");
      if((Name != null))
      {
        sb.Append(", Name: ");
        Name.ToString(sb);
      }
      if((Strategy_class != null))
      {
        sb.Append(", Strategy_class: ");
        Strategy_class.ToString(sb);
      }
      if((Strategy_options != null) && __isset.strategy_options)
      {
        sb.Append(", Strategy_options: ");
        Strategy_options.ToString(sb);
      }
      if(__isset.replication_factor)
      {
        sb.Append(", Replication_factor: ");
        Replication_factor.ToString(sb);
      }
      if((Cf_defs != null))
      {
        sb.Append(", Cf_defs: ");
        Cf_defs.ToString(sb);
      }
      if(__isset.durable_writes)
      {
        sb.Append(", Durable_writes: ");
        Durable_writes.ToString(sb);
      }
      sb.Append(')');
      return sb.ToString();
    }
  }

}
