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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Get unread messages where we were mentioned
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 400 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 400 MSG_ID_INVALID Invalid message ID provided.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.getUnreadMentions" />
///</summary>
[TlObject(0xf107e790)]
public sealed class RequestGetUnreadMentions : IRequest<MyTelegram.Schema.Messages.IMessages>
{
    public uint ConstructorId => 0xf107e790;
    ///<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 where to look for mentions
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// If set, considers only messages within the specified <a href="https://corefork.telegram.org/api/forum#forum-topics">forum topic</a>
    ///</summary>
    public int? TopMsgId { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/offsets">Offsets for pagination, for more info click here</a>
    ///</summary>
    public int OffsetId { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/offsets">Offsets for pagination, for more info click here</a>
    ///</summary>
    public int AddOffset { get; set; }

    ///<summary>
    /// Maximum number of results to return, <a href="https://corefork.telegram.org/api/offsets">see pagination</a>
    ///</summary>
    public int Limit { get; set; }

    ///<summary>
    /// Maximum message ID to return, <a href="https://corefork.telegram.org/api/offsets">see pagination</a>
    ///</summary>
    public int MaxId { get; set; }

    ///<summary>
    /// Minimum message ID to return, <a href="https://corefork.telegram.org/api/offsets">see pagination</a>
    ///</summary>
    public int MinId { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        if (Flags.IsBitSet(0)) { writer.Write(TopMsgId.Value); }
        writer.Write(OffsetId);
        writer.Write(AddOffset);
        writer.Write(Limit);
        writer.Write(MaxId);
        writer.Write(MinId);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        if (Flags.IsBitSet(0)) { TopMsgId = buffer.ReadInt32(); }
        OffsetId = buffer.ReadInt32();
        AddOffset = buffer.ReadInt32();
        Limit = buffer.ReadInt32();
        MaxId = buffer.ReadInt32();
        MinId = buffer.ReadInt32();
    }
}
