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

namespace MyTelegram.Schema;

///<summary>
/// Incoming messages were read
/// See <a href="https://corefork.telegram.org/constructor/updateReadHistoryInbox" />
///</summary>
[TlObject(0x9c974fdf)]
public sealed class TUpdateReadHistoryInbox : IUpdate
{
    public uint ConstructorId => 0x9c974fdf;
    ///<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>
    /// <a href="https://corefork.telegram.org/api/folders#peer-folders">Peer folder ID, for more info click here</a>
    ///</summary>
    public int? FolderId { get; set; }

    ///<summary>
    /// Peer
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer Peer { get; set; }

    ///<summary>
    /// Maximum ID of messages read
    ///</summary>
    public int MaxId { get; set; }

    ///<summary>
    /// Number of messages that are still unread
    ///</summary>
    public int StillUnreadCount { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/updates">Event count after generation</a>
    ///</summary>
    public int Pts { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/updates">Number of events that were generated</a>
    ///</summary>
    public int PtsCount { get; set; }

    public void ComputeFlag()
    {
        if (/*FolderId != 0 && */FolderId.HasValue) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(FolderId.Value); }
        writer.Write(Peer);
        writer.Write(MaxId);
        writer.Write(StillUnreadCount);
        writer.Write(Pts);
        writer.Write(PtsCount);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { FolderId = buffer.ReadInt32(); }
        Peer = buffer.Read<MyTelegram.Schema.IPeer>();
        MaxId = buffer.ReadInt32();
        StillUnreadCount = buffer.ReadInt32();
        Pts = buffer.ReadInt32();
        PtsCount = buffer.ReadInt32();
    }
}