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

namespace MyTelegram.Schema;

///<summary>
/// Message entity representing a block quote.
/// See <a href="https://corefork.telegram.org/constructor/messageEntityBlockquote" />
///</summary>
[TlObject(0xf1ccaaac)]
public sealed class TMessageEntityBlockquote : IMessageEntity
{
    public uint ConstructorId => 0xf1ccaaac;
    ///<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 quote is collapsed by default.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Collapsed { get; set; }

    ///<summary>
    /// Offset of message entity within message (in <a href="https://corefork.telegram.org/api/entities#entity-length">UTF-16 code units</a>)
    ///</summary>
    public int Offset { get; set; }

    ///<summary>
    /// Length of message entity within message (in <a href="https://corefork.telegram.org/api/entities#entity-length">UTF-16 code units</a>)
    ///</summary>
    public int Length { get; set; }

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

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Collapsed = true; }
        Offset = buffer.ReadInt32();
        Length = buffer.ReadInt32();
    }
}