/**
 * 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
{

  /// <summary>
  /// A TokenRange describes part of the Cassandra ring, it is a mapping from a range to
  /// endpoints responsible for that range.
  /// @param start_token The first token in the range
  /// @param end_token The last token in the range
  /// @param endpoints The endpoints responsible for the range (listed by their configured listen_address)
  /// @param rpc_endpoints The endpoints responsible for the range (listed by their configured rpc_address)
  /// </summary>
  [DataContract(Namespace="")]
  public partial class TokenRange : TBase
  {
    private List<string> _rpc_endpoints;
    private List<global::Apache.Cassandra.Test.EndpointDetails> _endpoint_details;

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

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

    [DataMember(Order = 0)]
    public List<string> Endpoints { get; set; }

    [DataMember(Order = 0)]
    public List<string> Rpc_endpoints
    {
      get
      {
        return _rpc_endpoints;
      }
      set
      {
        __isset.rpc_endpoints = true;
        this._rpc_endpoints = value;
      }
    }

    [DataMember(Order = 0)]
    public List<global::Apache.Cassandra.Test.EndpointDetails> Endpoint_details
    {
      get
      {
        return _endpoint_details;
      }
      set
      {
        __isset.endpoint_details = true;
        this._endpoint_details = value;
      }
    }


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

    #region XmlSerializer support

    public bool ShouldSerializeRpc_endpoints()
    {
      return __isset.rpc_endpoints;
    }

    public bool ShouldSerializeEndpoint_details()
    {
      return __isset.endpoint_details;
    }

    #endregion XmlSerializer support

    public TokenRange()
    {
    }

    public TokenRange(string start_token, string end_token, List<string> endpoints) : this()
    {
      this.Start_token = start_token;
      this.End_token = end_token;
      this.Endpoints = endpoints;
    }

    public TokenRange DeepCopy()
    {
      var tmp68 = new TokenRange();
      if((Start_token != null))
      {
        tmp68.Start_token = this.Start_token;
      }
      if((End_token != null))
      {
        tmp68.End_token = this.End_token;
      }
      if((Endpoints != null))
      {
        tmp68.Endpoints = this.Endpoints.DeepCopy();
      }
      if((Rpc_endpoints != null) && __isset.rpc_endpoints)
      {
        tmp68.Rpc_endpoints = this.Rpc_endpoints.DeepCopy();
      }
      tmp68.__isset.rpc_endpoints = this.__isset.rpc_endpoints;
      if((Endpoint_details != null) && __isset.endpoint_details)
      {
        tmp68.Endpoint_details = this.Endpoint_details.DeepCopy();
      }
      tmp68.__isset.endpoint_details = this.__isset.endpoint_details;
      return tmp68;
    }

    public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
    {
      iprot.IncrementRecursionDepth();
      try
      {
        bool isset_start_token = false;
        bool isset_end_token = false;
        bool isset_endpoints = 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)
              {
                Start_token = await iprot.ReadStringAsync(cancellationToken);
                isset_start_token = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 2:
              if (field.Type == TType.String)
              {
                End_token = await iprot.ReadStringAsync(cancellationToken);
                isset_end_token = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 3:
              if (field.Type == TType.List)
              {
                {
                  TList _list69 = await iprot.ReadListBeginAsync(cancellationToken);
                  Endpoints = new List<string>(_list69.Count);
                  for(int _i70 = 0; _i70 < _list69.Count; ++_i70)
                  {
                    string _elem71;
                    _elem71 = await iprot.ReadStringAsync(cancellationToken);
                    Endpoints.Add(_elem71);
                  }
                  await iprot.ReadListEndAsync(cancellationToken);
                }
                isset_endpoints = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 4:
              if (field.Type == TType.List)
              {
                {
                  TList _list72 = await iprot.ReadListBeginAsync(cancellationToken);
                  Rpc_endpoints = new List<string>(_list72.Count);
                  for(int _i73 = 0; _i73 < _list72.Count; ++_i73)
                  {
                    string _elem74;
                    _elem74 = await iprot.ReadStringAsync(cancellationToken);
                    Rpc_endpoints.Add(_elem74);
                  }
                  await iprot.ReadListEndAsync(cancellationToken);
                }
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 5:
              if (field.Type == TType.List)
              {
                {
                  TList _list75 = await iprot.ReadListBeginAsync(cancellationToken);
                  Endpoint_details = new List<global::Apache.Cassandra.Test.EndpointDetails>(_list75.Count);
                  for(int _i76 = 0; _i76 < _list75.Count; ++_i76)
                  {
                    global::Apache.Cassandra.Test.EndpointDetails _elem77;
                    _elem77 = new global::Apache.Cassandra.Test.EndpointDetails();
                    await _elem77.ReadAsync(iprot, cancellationToken);
                    Endpoint_details.Add(_elem77);
                  }
                  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);
        if (!isset_start_token)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_end_token)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_endpoints)
        {
          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("TokenRange");
        await oprot.WriteStructBeginAsync(struc, cancellationToken);
        var field = new TField();
        if((Start_token != null))
        {
          field.Name = "start_token";
          field.Type = TType.String;
          field.ID = 1;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteStringAsync(Start_token, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((End_token != null))
        {
          field.Name = "end_token";
          field.Type = TType.String;
          field.ID = 2;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteStringAsync(End_token, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Endpoints != null))
        {
          field.Name = "endpoints";
          field.Type = TType.List;
          field.ID = 3;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          {
            await oprot.WriteListBeginAsync(new TList(TType.String, Endpoints.Count), cancellationToken);
            foreach (string _iter78 in Endpoints)
            {
              await oprot.WriteStringAsync(_iter78, cancellationToken);
            }
            await oprot.WriteListEndAsync(cancellationToken);
          }
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Rpc_endpoints != null) && __isset.rpc_endpoints)
        {
          field.Name = "rpc_endpoints";
          field.Type = TType.List;
          field.ID = 4;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          {
            await oprot.WriteListBeginAsync(new TList(TType.String, Rpc_endpoints.Count), cancellationToken);
            foreach (string _iter79 in Rpc_endpoints)
            {
              await oprot.WriteStringAsync(_iter79, cancellationToken);
            }
            await oprot.WriteListEndAsync(cancellationToken);
          }
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Endpoint_details != null) && __isset.endpoint_details)
        {
          field.Name = "endpoint_details";
          field.Type = TType.List;
          field.ID = 5;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          {
            await oprot.WriteListBeginAsync(new TList(TType.Struct, Endpoint_details.Count), cancellationToken);
            foreach (global::Apache.Cassandra.Test.EndpointDetails _iter80 in Endpoint_details)
            {
              await _iter80.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 TokenRange other)) return false;
      if (ReferenceEquals(this, other)) return true;
      return System.Object.Equals(Start_token, other.Start_token)
        && System.Object.Equals(End_token, other.End_token)
        && TCollections.Equals(Endpoints, other.Endpoints)
        && ((__isset.rpc_endpoints == other.__isset.rpc_endpoints) && ((!__isset.rpc_endpoints) || (TCollections.Equals(Rpc_endpoints, other.Rpc_endpoints))))
        && ((__isset.endpoint_details == other.__isset.endpoint_details) && ((!__isset.endpoint_details) || (TCollections.Equals(Endpoint_details, other.Endpoint_details))));
    }

    public override int GetHashCode() {
      int hashcode = 157;
      unchecked {
        if((Start_token != null))
        {
          hashcode = (hashcode * 397) + Start_token.GetHashCode();
        }
        if((End_token != null))
        {
          hashcode = (hashcode * 397) + End_token.GetHashCode();
        }
        if((Endpoints != null))
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Endpoints);
        }
        if((Rpc_endpoints != null) && __isset.rpc_endpoints)
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Rpc_endpoints);
        }
        if((Endpoint_details != null) && __isset.endpoint_details)
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Endpoint_details);
        }
      }
      return hashcode;
    }

    public override string ToString()
    {
      var sb = new StringBuilder("TokenRange(");
      if((Start_token != null))
      {
        sb.Append(", Start_token: ");
        Start_token.ToString(sb);
      }
      if((End_token != null))
      {
        sb.Append(", End_token: ");
        End_token.ToString(sb);
      }
      if((Endpoints != null))
      {
        sb.Append(", Endpoints: ");
        Endpoints.ToString(sb);
      }
      if((Rpc_endpoints != null) && __isset.rpc_endpoints)
      {
        sb.Append(", Rpc_endpoints: ");
        Rpc_endpoints.ToString(sb);
      }
      if((Endpoint_details != null) && __isset.endpoint_details)
      {
        sb.Append(", Endpoint_details: ");
        Endpoint_details.ToString(sb);
      }
      sb.Append(')');
      return sb.ToString();
    }
  }

}
