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

namespace MyTelegram.Schema;

///<summary>
/// Info about a user in the <a href="https://corefork.telegram.org/api/reactions#paid-reactions">paid Star reactions leaderboard</a> for a message.
/// See <a href="https://corefork.telegram.org/constructor/messageReactor" />
///</summary>
[TlObject(0x4ba3a95a)]
public sealed class TMessageReactor : IMessageReactor
{
    public uint ConstructorId => 0x4ba3a95a;
    ///<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 set, the reactor is one of the most active reactors; may be unset if the reactor is the current user.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Top { get; set; }

    ///<summary>
    /// If set, this reactor is the current user.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool My { get; set; }

    ///<summary>
    /// If set, the reactor is anonymous.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Anonymous { get; set; }

    ///<summary>
    /// Identifier of the peer that reacted: may be unset for anonymous reactors different from the current user (i.e. if the current user sent an anonymous reaction <code>anonymous</code> will be set but this field will also be set).
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer? PeerId { get; set; }

    ///<summary>
    /// The number of sent Telegram Stars.
    ///</summary>
    public int Count { get; set; }

    public void ComputeFlag()
    {
        if (Top) { Flags = Flags.SetBit(0); }
        if (My) { Flags = Flags.SetBit(1); }
        if (Anonymous) { Flags = Flags.SetBit(2); }
        if (PeerId != null) { Flags = Flags.SetBit(3); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Top = true; }
        if (Flags.IsBitSet(1)) { My = true; }
        if (Flags.IsBitSet(2)) { Anonymous = true; }
        if (Flags.IsBitSet(3)) { PeerId = buffer.Read<MyTelegram.Schema.IPeer>(); }
        Count = buffer.ReadInt32();
    }
}