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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Press an inline callback button and get a callback answer from the bot
/// <para>Possible errors</para>
/// Code Type Description
/// 400 BOT_RESPONSE_TIMEOUT A timeout occurred while fetching data from the bot.
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 400 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 400 DATA_INVALID Encrypted data invalid.
/// 400 MESSAGE_ID_INVALID The provided message id is invalid.
/// 400 PASSWORD_MISSING You must <a href="https://corefork.telegram.org/api/srp">enable 2FA</a> before executing this operation.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// -503 Timeout Timeout while fetching data.
/// See <a href="https://corefork.telegram.org/method/messages.getBotCallbackAnswer" />
///</summary>
[TlObject(0x9342ca07)]
public sealed class RequestGetBotCallbackAnswer : IRequest<MyTelegram.Schema.Messages.IBotCallbackAnswer>
{
    public uint ConstructorId => 0x9342ca07;
    ///<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 this is a "play game" button
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Game { get; set; }

    ///<summary>
    /// Where was the inline keyboard sent
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// ID of the Message with the inline keyboard
    ///</summary>
    public int MsgId { get; set; }

    ///<summary>
    /// Callback data
    ///</summary>
    public ReadOnlyMemory<byte>? Data { get; set; }

    ///<summary>
    /// For buttons <a href="https://corefork.telegram.org/constructor/keyboardButtonCallback">requiring you to verify your identity with your 2FA password</a>, the SRP payload generated using <a href="https://corefork.telegram.org/api/srp">SRP</a>.
    /// See <a href="https://corefork.telegram.org/type/InputCheckPasswordSRP" />
    ///</summary>
    public MyTelegram.Schema.IInputCheckPasswordSRP? Password { get; set; }

    public void ComputeFlag()
    {
        if (Game) { Flags = Flags.SetBit(1); }
        if (Data != null) { Flags = Flags.SetBit(0); }
        if (Password != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(MsgId);
        if (Flags.IsBitSet(0)) { writer.Write(Data); }
        if (Flags.IsBitSet(2)) { writer.Write(Password); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Game = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        MsgId = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Data = buffer.ReadBytes(); }
        if (Flags.IsBitSet(2)) { Password = buffer.Read<MyTelegram.Schema.IInputCheckPasswordSRP>(); }
    }
}
