/**
 * 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>
  /// The semantics of start keys and tokens are slightly different.
  /// Keys are start-inclusive; tokens are start-exclusive.  Token
  /// ranges may also wrap -- that is, the end token may be less
  /// than the start one.  Thus, a range from keyX to keyX is a
  /// one-element range, but a range from tokenY to tokenY is the
  /// full ring.
  /// </summary>
  [DataContract(Namespace="")]
  public partial class KeyRange : TBase
  {
    private byte[] _start_key;
    private byte[] _end_key;
    private string _start_token;
    private string _end_token;

    [DataMember(Order = 0)]
    public byte[] Start_key
    {
      get
      {
        return _start_key;
      }
      set
      {
        __isset.start_key = true;
        this._start_key = value;
      }
    }

    [DataMember(Order = 0)]
    public byte[] End_key
    {
      get
      {
        return _end_key;
      }
      set
      {
        __isset.end_key = true;
        this._end_key = value;
      }
    }

    [DataMember(Order = 0)]
    public string Start_token
    {
      get
      {
        return _start_token;
      }
      set
      {
        __isset.start_token = true;
        this._start_token = value;
      }
    }

    [DataMember(Order = 0)]
    public string End_token
    {
      get
      {
        return _end_token;
      }
      set
      {
        __isset.end_token = true;
        this._end_token = value;
      }
    }

    [DataMember(Order = 0)]
    public int Count { get; set; }


    [DataMember(Order = 1)]
    public Isset __isset;
    [DataContract]
    public struct Isset
    {
      [DataMember]
      public bool start_key;
      [DataMember]
      public bool end_key;
      [DataMember]
      public bool start_token;
      [DataMember]
      public bool end_token;
    }

    #region XmlSerializer support

    public bool ShouldSerializeStart_key()
    {
      return __isset.start_key;
    }

    public bool ShouldSerializeEnd_key()
    {
      return __isset.end_key;
    }

    public bool ShouldSerializeStart_token()
    {
      return __isset.start_token;
    }

    public bool ShouldSerializeEnd_token()
    {
      return __isset.end_token;
    }

    #endregion XmlSerializer support

    public KeyRange()
    {
      this.Count = 100;
    }

    public KeyRange(int count) : this()
    {
      this.Count = count;
    }

    public KeyRange DeepCopy()
    {
      var tmp52 = new KeyRange();
      if((Start_key != null) && __isset.start_key)
      {
        tmp52.Start_key = this.Start_key.ToArray();
      }
      tmp52.__isset.start_key = this.__isset.start_key;
      if((End_key != null) && __isset.end_key)
      {
        tmp52.End_key = this.End_key.ToArray();
      }
      tmp52.__isset.end_key = this.__isset.end_key;
      if((Start_token != null) && __isset.start_token)
      {
        tmp52.Start_token = this.Start_token;
      }
      tmp52.__isset.start_token = this.__isset.start_token;
      if((End_token != null) && __isset.end_token)
      {
        tmp52.End_token = this.End_token;
      }
      tmp52.__isset.end_token = this.__isset.end_token;
      tmp52.Count = this.Count;
      return tmp52;
    }

    public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
    {
      iprot.IncrementRecursionDepth();
      try
      {
        bool isset_count = 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_key = await iprot.ReadBinaryAsync(cancellationToken);
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 2:
              if (field.Type == TType.String)
              {
                End_key = await iprot.ReadBinaryAsync(cancellationToken);
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 3:
              if (field.Type == TType.String)
              {
                Start_token = await iprot.ReadStringAsync(cancellationToken);
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 4:
              if (field.Type == TType.String)
              {
                End_token = await iprot.ReadStringAsync(cancellationToken);
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 5:
              if (field.Type == TType.I32)
              {
                Count = await iprot.ReadI32Async(cancellationToken);
                isset_count = 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_count)
        {
          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("KeyRange");
        await oprot.WriteStructBeginAsync(struc, cancellationToken);
        var field = new TField();
        if((Start_key != null) && __isset.start_key)
        {
          field.Name = "start_key";
          field.Type = TType.String;
          field.ID = 1;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteBinaryAsync(Start_key, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((End_key != null) && __isset.end_key)
        {
          field.Name = "end_key";
          field.Type = TType.String;
          field.ID = 2;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteBinaryAsync(End_key, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Start_token != null) && __isset.start_token)
        {
          field.Name = "start_token";
          field.Type = TType.String;
          field.ID = 3;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteStringAsync(Start_token, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((End_token != null) && __isset.end_token)
        {
          field.Name = "end_token";
          field.Type = TType.String;
          field.ID = 4;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteStringAsync(End_token, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        field.Name = "count";
        field.Type = TType.I32;
        field.ID = 5;
        await oprot.WriteFieldBeginAsync(field, cancellationToken);
        await oprot.WriteI32Async(Count, 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 KeyRange other)) return false;
      if (ReferenceEquals(this, other)) return true;
      return ((__isset.start_key == other.__isset.start_key) && ((!__isset.start_key) || (TCollections.Equals(Start_key, other.Start_key))))
        && ((__isset.end_key == other.__isset.end_key) && ((!__isset.end_key) || (TCollections.Equals(End_key, other.End_key))))
        && ((__isset.start_token == other.__isset.start_token) && ((!__isset.start_token) || (System.Object.Equals(Start_token, other.Start_token))))
        && ((__isset.end_token == other.__isset.end_token) && ((!__isset.end_token) || (System.Object.Equals(End_token, other.End_token))))
        && System.Object.Equals(Count, other.Count);
    }

    public override int GetHashCode() {
      int hashcode = 157;
      unchecked {
        if((Start_key != null) && __isset.start_key)
        {
          hashcode = (hashcode * 397) + Start_key.GetHashCode();
        }
        if((End_key != null) && __isset.end_key)
        {
          hashcode = (hashcode * 397) + End_key.GetHashCode();
        }
        if((Start_token != null) && __isset.start_token)
        {
          hashcode = (hashcode * 397) + Start_token.GetHashCode();
        }
        if((End_token != null) && __isset.end_token)
        {
          hashcode = (hashcode * 397) + End_token.GetHashCode();
        }
        hashcode = (hashcode * 397) + Count.GetHashCode();
      }
      return hashcode;
    }

    public override string ToString()
    {
      var sb = new StringBuilder("KeyRange(");
      int tmp53 = 0;
      if((Start_key != null) && __isset.start_key)
      {
        if(0 < tmp53++) { sb.Append(", "); }
        sb.Append("Start_key: ");
        Start_key.ToString(sb);
      }
      if((End_key != null) && __isset.end_key)
      {
        if(0 < tmp53++) { sb.Append(", "); }
        sb.Append("End_key: ");
        End_key.ToString(sb);
      }
      if((Start_token != null) && __isset.start_token)
      {
        if(0 < tmp53++) { sb.Append(", "); }
        sb.Append("Start_token: ");
        Start_token.ToString(sb);
      }
      if((End_token != null) && __isset.end_token)
      {
        if(0 < tmp53++) { sb.Append(", "); }
        sb.Append("End_token: ");
        End_token.ToString(sb);
      }
      if(0 < tmp53) { sb.Append(", "); }
      sb.Append("Count: ");
      Count.ToString(sb);
      sb.Append(')');
      return sb.ToString();
    }
  }

}
