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

namespace MyTelegram.Schema;

///<summary>
/// Button to request a user to <a href="https://corefork.telegram.org/method/messages.acceptUrlAuth">authorize</a> via URL using <a href="https://telegram.org/blog/privacy-discussions-web-bots#meet-seamless-web-bots">Seamless Telegram Login</a>.
/// See <a href="https://corefork.telegram.org/constructor/inputKeyboardButtonUrlAuth" />
///</summary>
[TlObject(0xd02e7fd4)]
public sealed class TInputKeyboardButtonUrlAuth : IKeyboardButton
{
    public uint ConstructorId => 0xd02e7fd4;
    ///<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>
    /// Set this flag to request the permission for your bot to send messages to the user.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool RequestWriteAccess { get; set; }

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

    ///<summary>
    /// New text of the button in forwarded messages.
    ///</summary>
    public string? FwdText { get; set; }

    ///<summary>
    /// An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. If the user refuses to provide authorization data, the original URL without information about the user will be opened. The data added is the same as described in <a href="https://corefork.telegram.org/widgets/login#receiving-authorization-data">Receiving authorization data</a>.<br>NOTE: You must always check the hash of the received data to verify the authentication and the integrity of the data as described in <a href="https://corefork.telegram.org/widgets/login#checking-authorization">Checking authorization</a>.
    ///</summary>
    public string Url { get; set; }

    ///<summary>
    /// Username of a bot, which will be used for user authorization. See <a href="https://corefork.telegram.org/widgets/login#setting-up-a-bot">Setting up a bot</a> for more details. If not specified, the current bot's username will be assumed. The url's domain must be the same as the domain linked with the bot. See <a href="https://corefork.telegram.org/widgets/login#linking-your-domain-to-the-bot">Linking your domain to the bot</a> for more details.
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser Bot { get; set; }

    public void ComputeFlag()
    {
        if (RequestWriteAccess) { Flags = Flags.SetBit(0); }
        if (FwdText != null) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Text);
        if (Flags.IsBitSet(1)) { writer.Write(FwdText); }
        writer.Write(Url);
        writer.Write(Bot);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { RequestWriteAccess = true; }
        Text = buffer.ReadString();
        if (Flags.IsBitSet(1)) { FwdText = buffer.ReadString(); }
        Url = buffer.ReadString();
        Bot = buffer.Read<MyTelegram.Schema.IInputUser>();
    }
}