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

namespace MyTelegram.Schema;

///<summary>
/// Animations associated with a message reaction
/// See <a href="https://corefork.telegram.org/constructor/availableReaction" />
///</summary>
[TlObject(0xc077ec01)]
public sealed class TAvailableReaction : IAvailableReaction
{
    public uint ConstructorId => 0xc077ec01;
    ///<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>
    /// If not set, the reaction can be added to new messages and enabled in chats.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Inactive { get; set; }

    ///<summary>
    /// Whether this reaction can only be used by Telegram Premium users
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Premium { get; set; }

    ///<summary>
    /// Reaction emoji
    ///</summary>
    public string Reaction { get; set; }

    ///<summary>
    /// Reaction description
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// Static icon for the reaction
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument StaticIcon { get; set; }

    ///<summary>
    /// The animated sticker to show when the user opens the reaction dropdown
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument AppearAnimation { get; set; }

    ///<summary>
    /// The animated sticker to show when the user hovers over the reaction
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument SelectAnimation { get; set; }

    ///<summary>
    /// The animated sticker to show when the reaction is chosen and activated
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument ActivateAnimation { get; set; }

    ///<summary>
    /// The background effect (still an animated sticker) to play under the <code>activate_animation</code>, when the reaction is chosen and activated
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument EffectAnimation { get; set; }

    ///<summary>
    /// The animation that plays around the button when you press an existing reaction (played together with <code>center_icon</code>).
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument? AroundAnimation { get; set; }

    ///<summary>
    /// The animation of the emoji inside the button when you press an existing reaction (played together with <code>around_animation</code>).
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument? CenterIcon { get; set; }

    public void ComputeFlag()
    {
        if (Inactive) { Flags = Flags.SetBit(0); }
        if (Premium) { Flags = Flags.SetBit(2); }
        if (AroundAnimation != null) { Flags = Flags.SetBit(1); }
        if (CenterIcon != null) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Reaction);
        writer.Write(Title);
        writer.Write(StaticIcon);
        writer.Write(AppearAnimation);
        writer.Write(SelectAnimation);
        writer.Write(ActivateAnimation);
        writer.Write(EffectAnimation);
        if (Flags.IsBitSet(1)) { writer.Write(AroundAnimation); }
        if (Flags.IsBitSet(1)) { writer.Write(CenterIcon); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Inactive = true; }
        if (Flags.IsBitSet(2)) { Premium = true; }
        Reaction = buffer.ReadString();
        Title = buffer.ReadString();
        StaticIcon = buffer.Read<MyTelegram.Schema.IDocument>();
        AppearAnimation = buffer.Read<MyTelegram.Schema.IDocument>();
        SelectAnimation = buffer.Read<MyTelegram.Schema.IDocument>();
        ActivateAnimation = buffer.Read<MyTelegram.Schema.IDocument>();
        EffectAnimation = buffer.Read<MyTelegram.Schema.IDocument>();
        if (Flags.IsBitSet(1)) { AroundAnimation = buffer.Read<MyTelegram.Schema.IDocument>(); }
        if (Flags.IsBitSet(1)) { CenterIcon = buffer.Read<MyTelegram.Schema.IDocument>(); }
    }
}