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

namespace MyTelegram.Schema;

///<summary>
/// Details about the authorization request, for more info <a href="https://corefork.telegram.org/api/url-authorization">click here »</a>
/// See <a href="https://corefork.telegram.org/constructor/urlAuthResultRequest" />
///</summary>
[TlObject(0x92d33a0e)]
public sealed class TUrlAuthResultRequest : IUrlAuthResult
{
    public uint ConstructorId => 0x92d33a0e;
    ///<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 bot would like to send messages to the user
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool RequestWriteAccess { get; set; }

    ///<summary>
    /// Username of a bot, which will be used for user authorization. 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://core.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/User" />
    ///</summary>
    public MyTelegram.Schema.IUser Bot { get; set; }

    ///<summary>
    /// The domain name of the website on which the user will log in.
    ///</summary>
    public string Domain { get; set; }

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

    }

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

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