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

namespace MyTelegram.Schema;

///<summary>
/// A collapsible details block
/// See <a href="https://corefork.telegram.org/constructor/pageBlockDetails" />
///</summary>
[TlObject(0x76768bed)]
public sealed class TPageBlockDetails : IPageBlock
{
    public uint ConstructorId => 0x76768bed;
    ///<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>
    /// Whether the block is open by default
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Open { get; set; }

    ///<summary>
    /// Block contents
    ///</summary>
    public TVector<MyTelegram.Schema.IPageBlock> Blocks { get; set; }

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

    public void ComputeFlag()
    {
        if (Open) { Flags = Flags.SetBit(0); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Open = true; }
        Blocks = buffer.Read<TVector<MyTelegram.Schema.IPageBlock>>();
        Title = buffer.Read<MyTelegram.Schema.IRichText>();
    }
}