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

namespace MyTelegram.Schema;

///<summary>
/// Represents a reaction bubble.
/// See <a href="https://corefork.telegram.org/constructor/mediaAreaSuggestedReaction" />
///</summary>
[TlObject(0x14455871)]
public sealed class TMediaAreaSuggestedReaction : IMediaArea
{
    public uint ConstructorId => 0x14455871;
    ///<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 the reaction bubble has a dark background.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Dark { get; set; }

    ///<summary>
    /// Whether the reaction bubble is mirrored (see <a href="https://corefork.telegram.org/api/stories#reactions">here »</a> for more info).
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Flipped { get; set; }

    ///<summary>
    /// The coordinates of the media area corresponding to the reaction button.
    /// See <a href="https://corefork.telegram.org/type/MediaAreaCoordinates" />
    ///</summary>
    public MyTelegram.Schema.IMediaAreaCoordinates Coordinates { get; set; }

    ///<summary>
    /// The reaction that should be sent when this area is clicked.
    /// See <a href="https://corefork.telegram.org/type/Reaction" />
    ///</summary>
    public MyTelegram.Schema.IReaction Reaction { get; set; }

    public void ComputeFlag()
    {
        if (Dark) { Flags = Flags.SetBit(0); }
        if (Flipped) { Flags = Flags.SetBit(1); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Dark = true; }
        if (Flags.IsBitSet(1)) { Flipped = true; }
        Coordinates = buffer.Read<MyTelegram.Schema.IMediaAreaCoordinates>();
        Reaction = buffer.Read<MyTelegram.Schema.IReaction>();
    }
}