/**
 * <auto-generated>
 * Autogenerated by Thrift Compiler (0.22.0)
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 * </auto-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 Thrift;
using Thrift.Collections;
using System.Runtime.Serialization;
using Thrift.Protocol;
using Thrift.Protocol.Entities;
using Thrift.Protocol.Utilities;
using Thrift.Transport;
using Thrift.Transport.Client;


#pragma warning disable IDE0079  // remove unnecessary pragmas
#pragma warning disable IDE0017  // object init can be simplified
#pragma warning disable IDE0028  // collection init can be simplified
#pragma warning disable IDE0305  // collection init can be simplified
#pragma warning disable IDE0034  // simplify default expression
#pragma warning disable IDE0066  // use switch expression
#pragma warning disable IDE0090  // simplify new expression
#pragma warning disable IDE0290  // use primary CTOR
#pragma warning disable IDE1006  // parts of the code use IDL spelling
#pragma warning disable CA1822   // empty DeepCopy() methods still non-static
#pragma warning disable IDE0083  // pattern matching "that is not SomeType" requires net5.0 but we still support earlier versions

namespace Byway.Thrift.Data
{

  /// <summary>
  /// 资源表
  /// </summary>
  [DataContract(Namespace="")]
  public partial class ArtTable : TBase
  {

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

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

    [DataMember(Order = 0)]
    public List<global::Byway.Thrift.Data.ArtItem> Items { get; set; }

    public ArtTable()
    {
    }

    public ArtTable(int tableId, string tableName, List<global::Byway.Thrift.Data.ArtItem> @items) : this()
    {
      this.TableId = tableId;
      this.TableName = tableName;
      this.Items = @items;
    }

    public ArtTable DeepCopy()
    {
      var tmp5 = new ArtTable();
      tmp5.TableId = this.TableId;
      if((TableName != null))
      {
        tmp5.TableName = this.TableName;
      }
      if((Items != null))
      {
        tmp5.Items = this.Items.DeepCopy();
      }
      return tmp5;
    }

    public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
    {
      iprot.IncrementRecursionDepth();
      try
      {
        bool isset_tableId = false;
        bool isset_tableName = false;
        bool isset_items = 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.I32)
              {
                TableId = await iprot.ReadI32Async(cancellationToken);
                isset_tableId = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 2:
              if (field.Type == TType.String)
              {
                TableName = await iprot.ReadStringAsync(cancellationToken);
                isset_tableName = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 3:
              if (field.Type == TType.List)
              {
                {
                  var _list6 = await iprot.ReadListBeginAsync(cancellationToken);
                  Items = new List<global::Byway.Thrift.Data.ArtItem>(_list6.Count);
                  for(int _i7 = 0; _i7 < _list6.Count; ++_i7)
                  {
                    global::Byway.Thrift.Data.ArtItem _elem8;
                    _elem8 = new global::Byway.Thrift.Data.ArtItem();
                    await _elem8.ReadAsync(iprot, cancellationToken);
                    Items.Add(_elem8);
                  }
                  await iprot.ReadListEndAsync(cancellationToken);
                }
                isset_items = 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_tableId)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_tableName)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_items)
        {
          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 tmp9 = new TStruct("ArtTable");
        await oprot.WriteStructBeginAsync(tmp9, cancellationToken);
        var tmp10 = new TField();
        tmp10.Name = "tableId";
        tmp10.Type = TType.I32;
        tmp10.ID = 1;
        await oprot.WriteFieldBeginAsync(tmp10, cancellationToken);
        await oprot.WriteI32Async(TableId, cancellationToken);
        await oprot.WriteFieldEndAsync(cancellationToken);
        if((TableName != null))
        {
          tmp10.Name = "tableName";
          tmp10.Type = TType.String;
          tmp10.ID = 2;
          await oprot.WriteFieldBeginAsync(tmp10, cancellationToken);
          await oprot.WriteStringAsync(TableName, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Items != null))
        {
          tmp10.Name = "items";
          tmp10.Type = TType.List;
          tmp10.ID = 3;
          await oprot.WriteFieldBeginAsync(tmp10, cancellationToken);
          await oprot.WriteListBeginAsync(new TList(TType.Struct, Items.Count), cancellationToken);
          foreach (global::Byway.Thrift.Data.ArtItem _iter11 in Items)
          {
            await _iter11.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 ArtTable other)) return false;
      if (ReferenceEquals(this, other)) return true;
      return global::System.Object.Equals(TableId, other.TableId)
        && global::System.Object.Equals(TableName, other.TableName)
        && TCollections.Equals(Items, other.Items);
    }

    public override int GetHashCode() {
      int hashcode = 157;
      unchecked {
        hashcode = (hashcode * 397) + TableId.GetHashCode();
        if((TableName != null))
        {
          hashcode = (hashcode * 397) + TableName.GetHashCode();
        }
        if((Items != null))
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Items);
        }
      }
      return hashcode;
    }

    public override string ToString()
    {
      var tmp12 = new StringBuilder("ArtTable(");
      tmp12.Append(", TableId: ");
      TableId.ToString(tmp12);
      if((TableName != null))
      {
        tmp12.Append(", TableName: ");
        TableName.ToString(tmp12);
      }
      if((Items != null))
      {
        tmp12.Append(", Items: ");
        Items.ToString(tmp12);
      }
      tmp12.Append(')');
      return tmp12.ToString();
    }
  }

}
