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

namespace MyTelegram.Schema;

///<summary>
/// Info about a <a href="https://corefork.telegram.org/api/saved-messages#tags">saved message reaction tag »</a>.
/// See <a href="https://corefork.telegram.org/constructor/savedReactionTag" />
///</summary>
[TlObject(0xcb6ff828)]
public sealed class TSavedReactionTag : ISavedReactionTag
{
    public uint ConstructorId => 0xcb6ff828;
    ///<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>
    /// <a href="https://corefork.telegram.org/api/reactions">Reaction</a> associated to the tag.
    /// See <a href="https://corefork.telegram.org/type/Reaction" />
    ///</summary>
    public MyTelegram.Schema.IReaction Reaction { get; set; }

    ///<summary>
    /// Custom tag name assigned by the user (max 12 UTF-8 chars).
    ///</summary>
    public string? Title { get; set; }

    ///<summary>
    /// Number of messages tagged with this tag.
    ///</summary>
    public int Count { get; set; }

    public void ComputeFlag()
    {
        if (Title != null) { Flags = Flags.SetBit(0); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Reaction = buffer.Read<MyTelegram.Schema.IReaction>();
        if (Flags.IsBitSet(0)) { Title = buffer.ReadString(); }
        Count = buffer.ReadInt32();
    }
}