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

namespace MyTelegram.Schema.Stories;

///<summary>
/// React to a story.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 400 REACTION_INVALID The specified reaction is invalid.
/// 400 STORY_ID_EMPTY You specified no story IDs.
/// 400 STORY_ID_INVALID The specified story ID is invalid.
/// See <a href="https://corefork.telegram.org/method/stories.sendReaction" />
///</summary>
[TlObject(0x7fd736b2)]
public sealed class RequestSendReaction : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0x7fd736b2;
    ///<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 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>
    /// The peer that sent the story
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// ID of the story to react to
    ///</summary>
    public int StoryId { get; set; }

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

    public void ComputeFlag()
    {
        if (AddToRecent) { Flags = Flags.SetBit(0); }

    }

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

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