/**
 * 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 slice range is a structure that stores basic range, ordering and limit information for a query that will return
  /// multiple columns. It could be thought of as Cassandra's version of LIMIT and ORDER BY
  /// 
  /// @param start. The column name to start the slice with. This attribute is not required, though there is no default value,
  ///               and can be safely set to '', i.e., an empty byte array, to start with the first column name. Otherwise, it
  ///               must a valid value under the rules of the Comparator defined for the given ColumnFamily.
  /// @param finish. The column name to stop the slice at. This attribute is not required, though there is no default value,
  ///                and can be safely set to an empty byte array to not stop until 'count' results are seen. Otherwise, it
  ///                must also be a valid value to the ColumnFamily Comparator.
  /// @param reversed. Whether the results should be ordered in reversed order. Similar to ORDER BY blah DESC in SQL.
  /// @param count. How many columns to return. Similar to LIMIT in SQL. May be arbitrarily large, but Thrift will
  ///               materialize the whole result into memory before returning it to the client, so be aware that you may
  ///               be better served by iterating through slices by passing the last value of one call in as the 'start'
  ///               of the next instead of increasing 'count' arbitrarily large.
  /// </summary>
  [DataContract(Namespace="")]
  public partial class SliceRange : TBase
  {

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

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

    [DataMember(Order = 0)]
    public bool Reversed { get; set; }

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

    public SliceRange()
    {
      this.Reversed = false;
      this.Count = 100;
    }

    public SliceRange(byte[] start, byte[] finish, bool reversed, int count) : this()
    {
      this.Start = start;
      this.Finish = finish;
      this.Reversed = reversed;
      this.Count = count;
    }

    public SliceRange DeepCopy()
    {
      var tmp36 = new SliceRange();
      if((Start != null))
      {
        tmp36.Start = this.Start.ToArray();
      }
      if((Finish != null))
      {
        tmp36.Finish = this.Finish.ToArray();
      }
      tmp36.Reversed = this.Reversed;
      tmp36.Count = this.Count;
      return tmp36;
    }

    public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
    {
      iprot.IncrementRecursionDepth();
      try
      {
        bool isset_start = false;
        bool isset_finish = false;
        bool isset_reversed = false;
        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 = await iprot.ReadBinaryAsync(cancellationToken);
                isset_start = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 2:
              if (field.Type == TType.String)
              {
                Finish = await iprot.ReadBinaryAsync(cancellationToken);
                isset_finish = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 3:
              if (field.Type == TType.Bool)
              {
                Reversed = await iprot.ReadBoolAsync(cancellationToken);
                isset_reversed = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 4:
              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_start)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_finish)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_reversed)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        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("SliceRange");
        await oprot.WriteStructBeginAsync(struc, cancellationToken);
        var field = new TField();
        if((Start != null))
        {
          field.Name = "start";
          field.Type = TType.String;
          field.ID = 1;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteBinaryAsync(Start, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Finish != null))
        {
          field.Name = "finish";
          field.Type = TType.String;
          field.ID = 2;
          await oprot.WriteFieldBeginAsync(field, cancellationToken);
          await oprot.WriteBinaryAsync(Finish, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        field.Name = "reversed";
        field.Type = TType.Bool;
        field.ID = 3;
        await oprot.WriteFieldBeginAsync(field, cancellationToken);
        await oprot.WriteBoolAsync(Reversed, cancellationToken);
        await oprot.WriteFieldEndAsync(cancellationToken);
        field.Name = "count";
        field.Type = TType.I32;
        field.ID = 4;
        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 SliceRange other)) return false;
      if (ReferenceEquals(this, other)) return true;
      return TCollections.Equals(Start, other.Start)
        && TCollections.Equals(Finish, other.Finish)
        && System.Object.Equals(Reversed, other.Reversed)
        && System.Object.Equals(Count, other.Count);
    }

    public override int GetHashCode() {
      int hashcode = 157;
      unchecked {
        if((Start != null))
        {
          hashcode = (hashcode * 397) + Start.GetHashCode();
        }
        if((Finish != null))
        {
          hashcode = (hashcode * 397) + Finish.GetHashCode();
        }
        hashcode = (hashcode * 397) + Reversed.GetHashCode();
        hashcode = (hashcode * 397) + Count.GetHashCode();
      }
      return hashcode;
    }

    public override string ToString()
    {
      var sb = new StringBuilder("SliceRange(");
      if((Start != null))
      {
        sb.Append(", Start: ");
        Start.ToString(sb);
      }
      if((Finish != null))
      {
        sb.Append(", Finish: ");
        Finish.ToString(sb);
      }
      sb.Append(", Reversed: ");
      Reversed.ToString(sb);
      sb.Append(", Count: ");
      Count.ToString(sb);
      sb.Append(')');
      return sb.ToString();
    }
  }

}
