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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Change the set of <a href="https://corefork.telegram.org/api/reactions">message reactions »</a> that can be used in a certain group, supergroup or channel
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHAT_ADMIN_REQUIRED You must be an admin in this chat to do this.
/// 400 CHAT_NOT_MODIFIED No changes were made to chat information because the new information you passed is identical to the current information.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// See <a href="https://corefork.telegram.org/method/messages.setChatAvailableReactions" />
///</summary>
[TlObject(0x864b2581)]
public sealed class RequestSetChatAvailableReactions : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0x864b2581;
    ///<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>
    /// Group where to apply changes
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// Allowed reaction emojis
    /// See <a href="https://corefork.telegram.org/type/ChatReactions" />
    ///</summary>
    public MyTelegram.Schema.IChatReactions AvailableReactions { get; set; }

    ///<summary>
    /// This flag may be used to impose a custom limit of unique reactions (i.e. a customizable version of <a href="https://corefork.telegram.org/api/config#reactions-uniq-max">appConfig.reactions_uniq_max</a>); this field and the other info set by the method will then be available to users in <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> and <a href="https://corefork.telegram.org/constructor/chatFull">chatFull</a>. <br>If this flag is not set, the previously configured <code>reactions_limit</code> will not be altered.
    ///</summary>
    public int? ReactionsLimit { get; set; }

    ///<summary>
    /// If this flag is set and a <a href="https://corefork.telegram.org/type/Bool">Bool</a> is passed, the method will enable or disable <a href="https://corefork.telegram.org/api/reactions#paid-reactions">paid message reactions »</a>. If this flag is not set, the previously stored setting will not be changed.
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? PaidEnabled { get; set; }

    public void ComputeFlag()
    {
        if (/*ReactionsLimit != 0 && */ReactionsLimit.HasValue) { Flags = Flags.SetBit(0); }
        if (PaidEnabled !=null) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(AvailableReactions);
        if (Flags.IsBitSet(0)) { writer.Write(ReactionsLimit.Value); }
        if (Flags.IsBitSet(1)) { writer.Write(PaidEnabled.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        AvailableReactions = buffer.Read<MyTelegram.Schema.IChatReactions>();
        if (Flags.IsBitSet(0)) { ReactionsLimit = buffer.ReadInt32(); }
        if (Flags.IsBitSet(1)) { PaidEnabled = buffer.Read(); }
    }
}
