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

namespace MyTelegram.Schema;

///<summary>
/// Callback button
/// See <a href="https://corefork.telegram.org/constructor/keyboardButtonCallback" />
///</summary>
[TlObject(0x35bbdb6b)]
public sealed class TKeyboardButtonCallback : IKeyboardButton
{
    public uint ConstructorId => 0x35bbdb6b;
    ///<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 should verify his identity by entering his <a href="https://corefork.telegram.org/api/srp">2FA SRP parameters</a> to the <a href="https://corefork.telegram.org/method/messages.getBotCallbackAnswer">messages.getBotCallbackAnswer</a> method. NOTE: telegram and the bot WILL NOT have access to the plaintext password, thanks to <a href="https://corefork.telegram.org/api/srp">SRP</a>. This button is mainly used by the official <a href="https://t.me/botfather">@botfather</a> bot, for verifying the user's identity before transferring ownership of a bot to another user.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool RequiresPassword { get; set; }

    ///<summary>
    /// Button text
    ///</summary>
    public string Text { get; set; }

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

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

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { RequiresPassword = true; }
        Text = buffer.ReadString();
        //Data = buffer.ReadBytes();
        Data = buffer.ReadString();
    }
}