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

namespace MyTelegram.Schema.Stories;

///<summary>
/// Reaction and view counters for a <a href="https://corefork.telegram.org/api/stories">story</a>
/// See <a href="https://corefork.telegram.org/constructor/stories.storyViewsList" />
///</summary>
[TlObject(0x59d78fc5)]
public sealed class TStoryViewsList : IStoryViewsList
{
    public uint ConstructorId => 0x59d78fc5;
    ///<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 results that can be fetched
    ///</summary>
    public int Count { get; set; }

    ///<summary>
    /// Total number of story views
    ///</summary>
    public int ViewsCount { get; set; }

    ///<summary>
    /// Total number of story forwards/reposts
    ///</summary>
    public int ForwardsCount { get; set; }

    ///<summary>
    /// Number of reactions that were added to the story
    ///</summary>
    public int ReactionsCount { get; set; }

    ///<summary>
    /// Story view date and reaction information
    ///</summary>
    public TVector<MyTelegram.Schema.IStoryView> Views { 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>
    /// Offset for pagination
    ///</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(ViewsCount);
        writer.Write(ForwardsCount);
        writer.Write(ReactionsCount);
        writer.Write(Views);
        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();
        ViewsCount = buffer.ReadInt32();
        ForwardsCount = buffer.ReadInt32();
        ReactionsCount = buffer.ReadInt32();
        Views = buffer.Read<TVector<MyTelegram.Schema.IStoryView>>();
        Chats = buffer.Read<TVector<MyTelegram.Schema.IChat>>();
        Users = buffer.Read<TVector<MyTelegram.Schema.IUser>>();
        if (Flags.IsBitSet(0)) { NextOffset = buffer.ReadString(); }
    }
}