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

namespace MyTelegram.Schema.Messages;

///<summary>
/// React to message.Starting from layer 159, the reaction will be sent from the peer specified using <a href="https://corefork.telegram.org/method/messages.saveDefaultSendAs">messages.saveDefaultSendAs</a>.
/// <para>Possible errors</para>
/// Code Type Description
/// 403 ANONYMOUS_REACTIONS_DISABLED Sorry, anonymous administrators cannot leave reactions or participate in polls.
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 400 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 403 CHAT_WRITE_FORBIDDEN You can't write in this chat.
/// 400 CUSTOM_REACTIONS_TOO_MANY Too many custom reactions were specified.
/// 400 DOCUMENT_INVALID The specified document is invalid.
/// 400 MESSAGE_ID_INVALID The provided message id is invalid.
/// 400 MESSAGE_NOT_MODIFIED The provided message data is identical to the previous message data, the message wasn't modified.
/// 400 MSG_ID_INVALID Invalid message ID provided.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 403 PREMIUM_ACCOUNT_REQUIRED A premium account is required to execute this action.
/// 400 REACTIONS_TOO_MANY The message already has exactly <code>reactions_uniq_max</code> reaction emojis, you can't react with a new emoji, see <a href="https://corefork.telegram.org/api/config#client-configuration">the docs for more info&nbsp;»</a>.
/// 400 REACTION_EMPTY Empty reaction provided.
/// 400 REACTION_INVALID The specified reaction is invalid.
/// 400 USER_BANNED_IN_CHANNEL You're banned from sending messages in supergroups/channels.
/// See <a href="https://corefork.telegram.org/method/messages.sendReaction" />
///</summary>
[TlObject(0xd30d78d4)]
public sealed class RequestSendReaction : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0xd30d78d4;
    ///<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 a bigger and longer reaction should be shown
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Big { get; set; }

    ///<summary>
    /// Whether to add this reaction to the <a href="https://corefork.telegram.org/api/reactions#recent-reactions">recent reactions list »</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool AddToRecent { get; set; }

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

    ///<summary>
    /// Message ID to react to
    ///</summary>
    public int MsgId { get; set; }

    ///<summary>
    /// A list of reactions
    ///</summary>
    public TVector<MyTelegram.Schema.IReaction>? Reaction { get; set; }

    public void ComputeFlag()
    {
        if (Big) { Flags = Flags.SetBit(1); }
        if (AddToRecent) { Flags = Flags.SetBit(2); }
        if (Reaction?.Count > 0) { Flags = Flags.SetBit(0); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(MsgId);
        if (Flags.IsBitSet(0)) { writer.Write(Reaction); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Big = true; }
        if (Flags.IsBitSet(2)) { AddToRecent = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        MsgId = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Reaction = buffer.Read<TVector<MyTelegram.Schema.IReaction>>(); }
    }
}
