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

namespace MyTelegram.Schema.Stories;

///<summary>
/// List of peers that reacted to or intercated with a specific <a href="https://corefork.telegram.org/api/stories">story</a>
/// See <a href="https://corefork.telegram.org/constructor/stories.storyReactionsList" />
///</summary>
[TlObject(0xaa5f789c)]
public sealed class TStoryReactionsList : IStoryReactionsList
{
    public uint ConstructorId => 0xaa5f789c;
    ///<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 or interacted with a specific story
    ///</summary>
    public TVector<MyTelegram.Schema.IStoryReaction> 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/stories.getStoryReactionsList">stories.getStoryReactionsList</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.IStoryReaction>>();
        Chats = buffer.Read<TVector<MyTelegram.Schema.IChat>>();
        Users = buffer.Read<TVector<MyTelegram.Schema.IUser>>();
        if (Flags.IsBitSet(0)) { NextOffset = buffer.ReadString(); }
    }
}