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

namespace MyTelegram.Schema.Messages;

///<summary>
/// List of peers that reacted to a specific message
/// See <a href="https://corefork.telegram.org/constructor/messages.messageReactionsList" />
///</summary>
[TlObject(0x31bd492d)]
public sealed class TMessageReactionsList : IMessageReactionsList
{
    public uint ConstructorId => 0x31bd492d;
    ///<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>
    /// Total number of reactions matching query
    ///</summary>
    public int Count { get; set; }

    ///<summary>
    /// List of peers that reacted to a specific message
    ///</summary>
    public TVector<MyTelegram.Schema.IMessagePeerReaction> Reactions { get; set; }

    ///<summary>
    /// Mentioned chats
    ///</summary>
    public TVector<MyTelegram.Schema.IChat> Chats { get; set; }

    ///<summary>
    /// Mentioned users
    ///</summary>
    public TVector<MyTelegram.Schema.IUser> Users { get; set; }

    ///<summary>
    /// If set, indicates the next offset to use to load more results by invoking <a href="https://corefork.telegram.org/method/messages.getMessageReactionsList">messages.getMessageReactionsList</a>.
    ///</summary>
    public string? NextOffset { get; set; }

    public void ComputeFlag()
    {
        if (NextOffset != null) { Flags = Flags.SetBit(0); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Count);
        writer.Write(Reactions);
        writer.Write(Chats);
        writer.Write(Users);
        if (Flags.IsBitSet(0)) { writer.Write(NextOffset); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Count = buffer.ReadInt32();
        Reactions = buffer.Read<TVector<MyTelegram.Schema.IMessagePeerReaction>>();
        Chats = buffer.Read<TVector<MyTelegram.Schema.IChat>>();
        Users = buffer.Read<TVector<MyTelegram.Schema.IUser>>();
        if (Flags.IsBitSet(0)) { NextOffset = buffer.ReadString(); }
    }
}