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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Enable or disable <a href="https://corefork.telegram.org/api/bots/attach">web bot attachment menu »</a>
/// <para>Possible errors</para>
/// Code Type Description
/// 400 BOT_INVALID This is not a valid bot.
/// See <a href="https://corefork.telegram.org/method/messages.toggleBotInAttachMenu" />
///</summary>
[TlObject(0x69f59d69)]
public sealed class RequestToggleBotInAttachMenu : IRequest<IBool>
{
    public uint ConstructorId => 0x69f59d69;
    ///<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 user authorizes the bot to write messages to them, if requested by <a href="https://corefork.telegram.org/constructor/attachMenuBot">attachMenuBot</a>.<code>request_write_access</code>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool WriteAllowed { get; set; }

    ///<summary>
    /// Bot ID
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser Bot { get; set; }

    ///<summary>
    /// Toggle
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool Enabled { get; set; }

    public void ComputeFlag()
    {
        if (WriteAllowed) { Flags = Flags.SetBit(0); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { WriteAllowed = true; }
        Bot = buffer.Read<MyTelegram.Schema.IInputUser>();
        Enabled = buffer.Read();
    }
}
