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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Mark <a href="https://corefork.telegram.org/api/reactions">message reactions »</a> as read
/// <para>Possible errors</para>
/// Code Type Description
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.readReactions" />
///</summary>
[TlObject(0x9ec44f93)]
public sealed class RequestReadReactions : IRequest<MyTelegram.Schema.Messages.IAffectedHistory>
{
    public uint ConstructorId => 0x9ec44f93;
    ///<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>
    /// Peer
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// Mark as read only reactions to messages within the specified <a href="https://corefork.telegram.org/api/forum#forum-topics">forum topic</a>
    ///</summary>
    public int? TopMsgId { get; set; }
    public MyTelegram.Schema.IInputPeer? SavedPeerId { 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(Peer);
        if (Flags.IsBitSet(0)) { writer.Write(TopMsgId.Value); }
        if (Flags.IsBitSet(1)) { writer.Write(SavedPeerId); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        if (Flags.IsBitSet(0)) { TopMsgId = buffer.ReadInt32(); }
        if (Flags.IsBitSet(1)) { SavedPeerId = buffer.Read<MyTelegram.Schema.IInputPeer>(); }
    }
}
