// <auto-generated/>
// ReSharper disable All

namespace MyTelegram.Schema;

///<summary>
/// Table
/// See <a href="https://corefork.telegram.org/constructor/pageBlockTable" />
///</summary>
[TlObject(0xbf4dea82)]
public sealed class TPageBlockTable : IPageBlock
{
    public uint ConstructorId => 0xbf4dea82;
    ///<summary>
    /// Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a>
    ///</summary>
    public int Flags { get; set; }

    ///<summary>
    /// Does the table have a visible border?
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Bordered { get; set; }

    ///<summary>
    /// Is the table striped?
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Striped { get; set; }

    ///<summary>
    /// Title
    /// See <a href="https://corefork.telegram.org/type/RichText" />
    ///</summary>
    public MyTelegram.Schema.IRichText Title { get; set; }

    ///<summary>
    /// Table rows
    ///</summary>
    public TVector<MyTelegram.Schema.IPageTableRow> Rows { get; set; }

    public void ComputeFlag()
    {
        if (Bordered) { Flags = Flags.SetBit(0); }
        if (Striped) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Title);
        writer.Write(Rows);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Bordered = true; }
        if (Flags.IsBitSet(1)) { Striped = true; }
        Title = buffer.Read<MyTelegram.Schema.IRichText>();
        Rows = buffer.Read<TVector<MyTelegram.Schema.IPageTableRow>>();
    }
}