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

namespace MyTelegram.Schema;

///<summary>
/// Button to request a user to authorize via URL using <a href="https://telegram.org/blog/privacy-discussions-web-bots#meet-seamless-web-bots">Seamless Telegram Login</a>. When the user clicks on such a button, <a href="https://corefork.telegram.org/method/messages.requestUrlAuth">messages.requestUrlAuth</a> should be called, providing the <code>button_id</code> and the ID of the container message. The returned <a href="https://corefork.telegram.org/constructor/urlAuthResultRequest">urlAuthResultRequest</a> object will contain more details about the authorization request (<code>request_write_access</code> if the bot would like to send messages to the user along with the username of the bot which will be used for user authorization). Finally, the user can choose to call <a href="https://corefork.telegram.org/method/messages.acceptUrlAuth">messages.acceptUrlAuth</a> to get a <a href="https://corefork.telegram.org/constructor/urlAuthResultAccepted">urlAuthResultAccepted</a> with the URL to open instead of the <code>url</code> of this constructor, or a <a href="https://corefork.telegram.org/constructor/urlAuthResultDefault">urlAuthResultDefault</a>, in which case the <code>url</code> of this constructor must be opened, instead. If the user refuses the authorization request but still wants to open the link, the <code>url</code> of this constructor must be used.
/// See <a href="https://corefork.telegram.org/constructor/keyboardButtonUrlAuth" />
///</summary>
[TlObject(0x10b78d29)]
public sealed class TKeyboardButtonUrlAuth : IKeyboardButton
{
    public uint ConstructorId => 0x10b78d29;
    ///<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>
    /// Button label
    ///</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><br><strong>NOTE</strong>: Services must <strong>always</strong> 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>
    /// ID of the button to pass to <a href="https://corefork.telegram.org/method/messages.requestUrlAuth">messages.requestUrlAuth</a>
    ///</summary>
    public int ButtonId { get; set; }

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

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Text = buffer.ReadString();
        if (Flags.IsBitSet(0)) { FwdText = buffer.ReadString(); }
        Url = buffer.ReadString();
        ButtonId = buffer.ReadInt32();
    }
}