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

namespace MyTelegram.Schema.Stories;

///<summary>
/// Full list of active (or active and hidden) <a href="https://corefork.telegram.org/api/stories#watching-stories">stories</a>.
/// See <a href="https://corefork.telegram.org/constructor/stories.allStories" />
///</summary>
[TlObject(0x6efc5e81)]
public sealed class TAllStories : IAllStories
{
    public uint ConstructorId => 0x6efc5e81;
    ///<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 more results can be fetched as <a href="https://corefork.telegram.org/api/stories#watching-stories">described here »</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HasMore { get; set; }

    ///<summary>
    /// Total number of active (or active and hidden) stories
    ///</summary>
    public int Count { get; set; }

    ///<summary>
    /// State to use for pagination
    ///</summary>
    public string State { get; set; }

    ///<summary>
    /// Stories
    ///</summary>
    public TVector<MyTelegram.Schema.IPeerStories> PeerStories { 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>
    /// Current <a href="https://corefork.telegram.org/api/stories#stealth-mode">stealth mode</a> information
    /// See <a href="https://corefork.telegram.org/type/StoriesStealthMode" />
    ///</summary>
    public MyTelegram.Schema.IStoriesStealthMode StealthMode { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Count);
        writer.Write(State);
        writer.Write(PeerStories);
        writer.Write(Chats);
        writer.Write(Users);
        writer.Write(StealthMode);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { HasMore = true; }
        Count = buffer.ReadInt32();
        State = buffer.ReadString();
        PeerStories = buffer.Read<TVector<MyTelegram.Schema.IPeerStories>>();
        Chats = buffer.Read<TVector<MyTelegram.Schema.IChat>>();
        Users = buffer.Read<TVector<MyTelegram.Schema.IUser>>();
        StealthMode = buffer.Read<MyTelegram.Schema.IStoriesStealthMode>();
    }
}