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

namespace MyTelegram.Schema;

///<summary>
/// The specified <a href="https://corefork.telegram.org/api/channel">channel/supergroup</a> messages were read
/// See <a href="https://corefork.telegram.org/constructor/updateChannelReadMessagesContents" />
///</summary>
[TlObject(0x25f324f7)]
public sealed class TUpdateChannelReadMessagesContents : IUpdate
{
    public uint ConstructorId => 0x25f324f7;
    ///<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/channel">Channel/supergroup</a> ID
    ///</summary>
    public long ChannelId { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/forum#forum-topics">Forum topic ID</a>.
    ///</summary>
    public int? TopMsgId { get; set; }
    public MyTelegram.Schema.IPeer? SavedPeerId { get; set; }

    ///<summary>
    /// IDs of messages that were read
    ///</summary>
    public TVector<int> Messages { get; set; }

    public void ComputeFlag()
    {
        if (/*TopMsgId != 0 && */TopMsgId.HasValue) { Flags = Flags.SetBit(0); }
        if (SavedPeerId != null) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(ChannelId);
        if (Flags.IsBitSet(0)) { writer.Write(TopMsgId.Value); }
        if (Flags.IsBitSet(1)) { writer.Write(SavedPeerId); }
        writer.Write(Messages);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        ChannelId = buffer.ReadInt64();
        if (Flags.IsBitSet(0)) { TopMsgId = buffer.ReadInt32(); }
        if (Flags.IsBitSet(1)) { SavedPeerId = buffer.Read<MyTelegram.Schema.IPeer>(); }
        Messages = buffer.Read<TVector<int>>();
    }
}