// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// URLAuthResultRequest represents TL type `urlAuthResultRequest#3cd623ec`.
// Details about the authorization request, for more info click here »¹
//
// Links:
//  1. https://core.telegram.org/api/url-authorization
//
// See https://core.telegram.org/constructor/urlAuthResultRequest for reference.
type URLAuthResultRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the bot would like to send messages to the user
	RequestWriteAccess bool
	// RequestPhoneNumber field of URLAuthResultRequest.
	RequestPhoneNumber bool
	// MatchCodesFirst field of URLAuthResultRequest.
	MatchCodesFirst bool
	// IsApp field of URLAuthResultRequest.
	IsApp bool
	// 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 Linking your domain to the bot¹ for more details.
	//
	// Links:
	//  1) https://core.telegram.org/widgets/login#linking-your-domain-to-the-bot
	Bot UserClass
	// The domain name of the website on which the user will log in.
	Domain string
	// Browser field of URLAuthResultRequest.
	//
	// Use SetBrowser and GetBrowser helpers.
	Browser string
	// Platform field of URLAuthResultRequest.
	//
	// Use SetPlatform and GetPlatform helpers.
	Platform string
	// IP field of URLAuthResultRequest.
	//
	// Use SetIP and GetIP helpers.
	IP string
	// Region field of URLAuthResultRequest.
	//
	// Use SetRegion and GetRegion helpers.
	Region string
	// MatchCodes field of URLAuthResultRequest.
	//
	// Use SetMatchCodes and GetMatchCodes helpers.
	MatchCodes []string
	// UserIDHint field of URLAuthResultRequest.
	//
	// Use SetUserIDHint and GetUserIDHint helpers.
	UserIDHint int64
	// VerifiedAppName field of URLAuthResultRequest.
	//
	// Use SetVerifiedAppName and GetVerifiedAppName helpers.
	VerifiedAppName string
}

// URLAuthResultRequestTypeID is TL type id of URLAuthResultRequest.
const URLAuthResultRequestTypeID = 0x3cd623ec

// construct implements constructor of URLAuthResultClass.
func (u URLAuthResultRequest) construct() URLAuthResultClass { return &u }

// Ensuring interfaces in compile-time for URLAuthResultRequest.
var (
	_ bin.Encoder     = &URLAuthResultRequest{}
	_ bin.Decoder     = &URLAuthResultRequest{}
	_ bin.BareEncoder = &URLAuthResultRequest{}
	_ bin.BareDecoder = &URLAuthResultRequest{}

	_ URLAuthResultClass = &URLAuthResultRequest{}
)

func (u *URLAuthResultRequest) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.Flags.Zero()) {
		return false
	}
	if !(u.RequestWriteAccess == false) {
		return false
	}
	if !(u.RequestPhoneNumber == false) {
		return false
	}
	if !(u.MatchCodesFirst == false) {
		return false
	}
	if !(u.IsApp == false) {
		return false
	}
	if !(u.Bot == nil) {
		return false
	}
	if !(u.Domain == "") {
		return false
	}
	if !(u.Browser == "") {
		return false
	}
	if !(u.Platform == "") {
		return false
	}
	if !(u.IP == "") {
		return false
	}
	if !(u.Region == "") {
		return false
	}
	if !(u.MatchCodes == nil) {
		return false
	}
	if !(u.UserIDHint == 0) {
		return false
	}
	if !(u.VerifiedAppName == "") {
		return false
	}

	return true
}

// String implements fmt.Stringer.
func (u *URLAuthResultRequest) String() string {
	if u == nil {
		return "URLAuthResultRequest(nil)"
	}
	type Alias URLAuthResultRequest
	return fmt.Sprintf("URLAuthResultRequest%+v", Alias(*u))
}

// FillFrom fills URLAuthResultRequest from given interface.
func (u *URLAuthResultRequest) FillFrom(from interface {
	GetRequestWriteAccess() (value bool)
	GetRequestPhoneNumber() (value bool)
	GetMatchCodesFirst() (value bool)
	GetIsApp() (value bool)
	GetBot() (value UserClass)
	GetDomain() (value string)
	GetBrowser() (value string, ok bool)
	GetPlatform() (value string, ok bool)
	GetIP() (value string, ok bool)
	GetRegion() (value string, ok bool)
	GetMatchCodes() (value []string, ok bool)
	GetUserIDHint() (value int64, ok bool)
	GetVerifiedAppName() (value string, ok bool)
}) {
	u.RequestWriteAccess = from.GetRequestWriteAccess()
	u.RequestPhoneNumber = from.GetRequestPhoneNumber()
	u.MatchCodesFirst = from.GetMatchCodesFirst()
	u.IsApp = from.GetIsApp()
	u.Bot = from.GetBot()
	u.Domain = from.GetDomain()
	if val, ok := from.GetBrowser(); ok {
		u.Browser = val
	}

	if val, ok := from.GetPlatform(); ok {
		u.Platform = val
	}

	if val, ok := from.GetIP(); ok {
		u.IP = val
	}

	if val, ok := from.GetRegion(); ok {
		u.Region = val
	}

	if val, ok := from.GetMatchCodes(); ok {
		u.MatchCodes = val
	}

	if val, ok := from.GetUserIDHint(); ok {
		u.UserIDHint = val
	}

	if val, ok := from.GetVerifiedAppName(); ok {
		u.VerifiedAppName = val
	}

}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*URLAuthResultRequest) TypeID() uint32 {
	return URLAuthResultRequestTypeID
}

// TypeName returns name of type in TL schema.
func (*URLAuthResultRequest) TypeName() string {
	return "urlAuthResultRequest"
}

// TypeInfo returns info about TL type.
func (u *URLAuthResultRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "urlAuthResultRequest",
		ID:   URLAuthResultRequestTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "RequestWriteAccess",
			SchemaName: "request_write_access",
			Null:       !u.Flags.Has(0),
		},
		{
			Name:       "RequestPhoneNumber",
			SchemaName: "request_phone_number",
			Null:       !u.Flags.Has(1),
		},
		{
			Name:       "MatchCodesFirst",
			SchemaName: "match_codes_first",
			Null:       !u.Flags.Has(5),
		},
		{
			Name:       "IsApp",
			SchemaName: "is_app",
			Null:       !u.Flags.Has(6),
		},
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
		{
			Name:       "Domain",
			SchemaName: "domain",
		},
		{
			Name:       "Browser",
			SchemaName: "browser",
			Null:       !u.Flags.Has(2),
		},
		{
			Name:       "Platform",
			SchemaName: "platform",
			Null:       !u.Flags.Has(2),
		},
		{
			Name:       "IP",
			SchemaName: "ip",
			Null:       !u.Flags.Has(2),
		},
		{
			Name:       "Region",
			SchemaName: "region",
			Null:       !u.Flags.Has(2),
		},
		{
			Name:       "MatchCodes",
			SchemaName: "match_codes",
			Null:       !u.Flags.Has(3),
		},
		{
			Name:       "UserIDHint",
			SchemaName: "user_id_hint",
			Null:       !u.Flags.Has(4),
		},
		{
			Name:       "VerifiedAppName",
			SchemaName: "verified_app_name",
			Null:       !u.Flags.Has(7),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (u *URLAuthResultRequest) SetFlags() {
	if !(u.RequestWriteAccess == false) {
		u.Flags.Set(0)
	}
	if !(u.RequestPhoneNumber == false) {
		u.Flags.Set(1)
	}
	if !(u.MatchCodesFirst == false) {
		u.Flags.Set(5)
	}
	if !(u.IsApp == false) {
		u.Flags.Set(6)
	}
	if !(u.Browser == "") {
		u.Flags.Set(2)
	}
	if !(u.Platform == "") {
		u.Flags.Set(2)
	}
	if !(u.IP == "") {
		u.Flags.Set(2)
	}
	if !(u.Region == "") {
		u.Flags.Set(2)
	}
	if !(u.MatchCodes == nil) {
		u.Flags.Set(3)
	}
	if !(u.UserIDHint == 0) {
		u.Flags.Set(4)
	}
	if !(u.VerifiedAppName == "") {
		u.Flags.Set(7)
	}
}

// Encode implements bin.Encoder.
func (u *URLAuthResultRequest) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode urlAuthResultRequest#3cd623ec as nil")
	}
	b.PutID(URLAuthResultRequestTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *URLAuthResultRequest) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode urlAuthResultRequest#3cd623ec as nil")
	}
	u.SetFlags()
	if err := u.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode urlAuthResultRequest#3cd623ec: field flags: %w", err)
	}
	if u.Bot == nil {
		return fmt.Errorf("unable to encode urlAuthResultRequest#3cd623ec: field bot is nil")
	}
	if err := u.Bot.Encode(b); err != nil {
		return fmt.Errorf("unable to encode urlAuthResultRequest#3cd623ec: field bot: %w", err)
	}
	b.PutString(u.Domain)
	if u.Flags.Has(2) {
		b.PutString(u.Browser)
	}
	if u.Flags.Has(2) {
		b.PutString(u.Platform)
	}
	if u.Flags.Has(2) {
		b.PutString(u.IP)
	}
	if u.Flags.Has(2) {
		b.PutString(u.Region)
	}
	if u.Flags.Has(3) {
		b.PutVectorHeader(len(u.MatchCodes))
		for _, v := range u.MatchCodes {
			b.PutString(v)
		}
	}
	if u.Flags.Has(4) {
		b.PutLong(u.UserIDHint)
	}
	if u.Flags.Has(7) {
		b.PutString(u.VerifiedAppName)
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *URLAuthResultRequest) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode urlAuthResultRequest#3cd623ec to nil")
	}
	if err := b.ConsumeID(URLAuthResultRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *URLAuthResultRequest) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode urlAuthResultRequest#3cd623ec to nil")
	}
	{
		if err := u.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field flags: %w", err)
		}
	}
	u.RequestWriteAccess = u.Flags.Has(0)
	u.RequestPhoneNumber = u.Flags.Has(1)
	u.MatchCodesFirst = u.Flags.Has(5)
	u.IsApp = u.Flags.Has(6)
	{
		value, err := DecodeUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field bot: %w", err)
		}
		u.Bot = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field domain: %w", err)
		}
		u.Domain = value
	}
	if u.Flags.Has(2) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field browser: %w", err)
		}
		u.Browser = value
	}
	if u.Flags.Has(2) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field platform: %w", err)
		}
		u.Platform = value
	}
	if u.Flags.Has(2) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field ip: %w", err)
		}
		u.IP = value
	}
	if u.Flags.Has(2) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field region: %w", err)
		}
		u.Region = value
	}
	if u.Flags.Has(3) {
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field match_codes: %w", err)
		}

		if headerLen > 0 {
			u.MatchCodes = make([]string, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field match_codes: %w", err)
			}
			u.MatchCodes = append(u.MatchCodes, value)
		}
	}
	if u.Flags.Has(4) {
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field user_id_hint: %w", err)
		}
		u.UserIDHint = value
	}
	if u.Flags.Has(7) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#3cd623ec: field verified_app_name: %w", err)
		}
		u.VerifiedAppName = value
	}
	return nil
}

// SetRequestWriteAccess sets value of RequestWriteAccess conditional field.
func (u *URLAuthResultRequest) SetRequestWriteAccess(value bool) {
	if value {
		u.Flags.Set(0)
		u.RequestWriteAccess = true
	} else {
		u.Flags.Unset(0)
		u.RequestWriteAccess = false
	}
}

// GetRequestWriteAccess returns value of RequestWriteAccess conditional field.
func (u *URLAuthResultRequest) GetRequestWriteAccess() (value bool) {
	if u == nil {
		return
	}
	return u.Flags.Has(0)
}

// SetRequestPhoneNumber sets value of RequestPhoneNumber conditional field.
func (u *URLAuthResultRequest) SetRequestPhoneNumber(value bool) {
	if value {
		u.Flags.Set(1)
		u.RequestPhoneNumber = true
	} else {
		u.Flags.Unset(1)
		u.RequestPhoneNumber = false
	}
}

// GetRequestPhoneNumber returns value of RequestPhoneNumber conditional field.
func (u *URLAuthResultRequest) GetRequestPhoneNumber() (value bool) {
	if u == nil {
		return
	}
	return u.Flags.Has(1)
}

// SetMatchCodesFirst sets value of MatchCodesFirst conditional field.
func (u *URLAuthResultRequest) SetMatchCodesFirst(value bool) {
	if value {
		u.Flags.Set(5)
		u.MatchCodesFirst = true
	} else {
		u.Flags.Unset(5)
		u.MatchCodesFirst = false
	}
}

// GetMatchCodesFirst returns value of MatchCodesFirst conditional field.
func (u *URLAuthResultRequest) GetMatchCodesFirst() (value bool) {
	if u == nil {
		return
	}
	return u.Flags.Has(5)
}

// SetIsApp sets value of IsApp conditional field.
func (u *URLAuthResultRequest) SetIsApp(value bool) {
	if value {
		u.Flags.Set(6)
		u.IsApp = true
	} else {
		u.Flags.Unset(6)
		u.IsApp = false
	}
}

// GetIsApp returns value of IsApp conditional field.
func (u *URLAuthResultRequest) GetIsApp() (value bool) {
	if u == nil {
		return
	}
	return u.Flags.Has(6)
}

// GetBot returns value of Bot field.
func (u *URLAuthResultRequest) GetBot() (value UserClass) {
	if u == nil {
		return
	}
	return u.Bot
}

// GetDomain returns value of Domain field.
func (u *URLAuthResultRequest) GetDomain() (value string) {
	if u == nil {
		return
	}
	return u.Domain
}

// SetBrowser sets value of Browser conditional field.
func (u *URLAuthResultRequest) SetBrowser(value string) {
	u.Flags.Set(2)
	u.Browser = value
}

// GetBrowser returns value of Browser conditional field and
// boolean which is true if field was set.
func (u *URLAuthResultRequest) GetBrowser() (value string, ok bool) {
	if u == nil {
		return
	}
	if !u.Flags.Has(2) {
		return value, false
	}
	return u.Browser, true
}

// SetPlatform sets value of Platform conditional field.
func (u *URLAuthResultRequest) SetPlatform(value string) {
	u.Flags.Set(2)
	u.Platform = value
}

// GetPlatform returns value of Platform conditional field and
// boolean which is true if field was set.
func (u *URLAuthResultRequest) GetPlatform() (value string, ok bool) {
	if u == nil {
		return
	}
	if !u.Flags.Has(2) {
		return value, false
	}
	return u.Platform, true
}

// SetIP sets value of IP conditional field.
func (u *URLAuthResultRequest) SetIP(value string) {
	u.Flags.Set(2)
	u.IP = value
}

// GetIP returns value of IP conditional field and
// boolean which is true if field was set.
func (u *URLAuthResultRequest) GetIP() (value string, ok bool) {
	if u == nil {
		return
	}
	if !u.Flags.Has(2) {
		return value, false
	}
	return u.IP, true
}

// SetRegion sets value of Region conditional field.
func (u *URLAuthResultRequest) SetRegion(value string) {
	u.Flags.Set(2)
	u.Region = value
}

// GetRegion returns value of Region conditional field and
// boolean which is true if field was set.
func (u *URLAuthResultRequest) GetRegion() (value string, ok bool) {
	if u == nil {
		return
	}
	if !u.Flags.Has(2) {
		return value, false
	}
	return u.Region, true
}

// SetMatchCodes sets value of MatchCodes conditional field.
func (u *URLAuthResultRequest) SetMatchCodes(value []string) {
	u.Flags.Set(3)
	u.MatchCodes = value
}

// GetMatchCodes returns value of MatchCodes conditional field and
// boolean which is true if field was set.
func (u *URLAuthResultRequest) GetMatchCodes() (value []string, ok bool) {
	if u == nil {
		return
	}
	if !u.Flags.Has(3) {
		return value, false
	}
	return u.MatchCodes, true
}

// SetUserIDHint sets value of UserIDHint conditional field.
func (u *URLAuthResultRequest) SetUserIDHint(value int64) {
	u.Flags.Set(4)
	u.UserIDHint = value
}

// GetUserIDHint returns value of UserIDHint conditional field and
// boolean which is true if field was set.
func (u *URLAuthResultRequest) GetUserIDHint() (value int64, ok bool) {
	if u == nil {
		return
	}
	if !u.Flags.Has(4) {
		return value, false
	}
	return u.UserIDHint, true
}

// SetVerifiedAppName sets value of VerifiedAppName conditional field.
func (u *URLAuthResultRequest) SetVerifiedAppName(value string) {
	u.Flags.Set(7)
	u.VerifiedAppName = value
}

// GetVerifiedAppName returns value of VerifiedAppName conditional field and
// boolean which is true if field was set.
func (u *URLAuthResultRequest) GetVerifiedAppName() (value string, ok bool) {
	if u == nil {
		return
	}
	if !u.Flags.Has(7) {
		return value, false
	}
	return u.VerifiedAppName, true
}

// URLAuthResultAccepted represents TL type `urlAuthResultAccepted#623a8fa0`.
// Details about an accepted authorization request, for more info click here »¹
//
// Links:
//  1. https://core.telegram.org/api/url-authorization
//
// See https://core.telegram.org/constructor/urlAuthResultAccepted for reference.
type URLAuthResultAccepted struct {
	// Flags field of URLAuthResultAccepted.
	Flags bin.Fields
	// The URL name of the website on which the user has logged in.
	//
	// Use SetURL and GetURL helpers.
	URL string
}

// URLAuthResultAcceptedTypeID is TL type id of URLAuthResultAccepted.
const URLAuthResultAcceptedTypeID = 0x623a8fa0

// construct implements constructor of URLAuthResultClass.
func (u URLAuthResultAccepted) construct() URLAuthResultClass { return &u }

// Ensuring interfaces in compile-time for URLAuthResultAccepted.
var (
	_ bin.Encoder     = &URLAuthResultAccepted{}
	_ bin.Decoder     = &URLAuthResultAccepted{}
	_ bin.BareEncoder = &URLAuthResultAccepted{}
	_ bin.BareDecoder = &URLAuthResultAccepted{}

	_ URLAuthResultClass = &URLAuthResultAccepted{}
)

func (u *URLAuthResultAccepted) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.Flags.Zero()) {
		return false
	}
	if !(u.URL == "") {
		return false
	}

	return true
}

// String implements fmt.Stringer.
func (u *URLAuthResultAccepted) String() string {
	if u == nil {
		return "URLAuthResultAccepted(nil)"
	}
	type Alias URLAuthResultAccepted
	return fmt.Sprintf("URLAuthResultAccepted%+v", Alias(*u))
}

// FillFrom fills URLAuthResultAccepted from given interface.
func (u *URLAuthResultAccepted) FillFrom(from interface {
	GetURL() (value string, ok bool)
}) {
	if val, ok := from.GetURL(); ok {
		u.URL = val
	}

}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*URLAuthResultAccepted) TypeID() uint32 {
	return URLAuthResultAcceptedTypeID
}

// TypeName returns name of type in TL schema.
func (*URLAuthResultAccepted) TypeName() string {
	return "urlAuthResultAccepted"
}

// TypeInfo returns info about TL type.
func (u *URLAuthResultAccepted) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "urlAuthResultAccepted",
		ID:   URLAuthResultAcceptedTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
			Null:       !u.Flags.Has(0),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (u *URLAuthResultAccepted) SetFlags() {
	if !(u.URL == "") {
		u.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func (u *URLAuthResultAccepted) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode urlAuthResultAccepted#623a8fa0 as nil")
	}
	b.PutID(URLAuthResultAcceptedTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *URLAuthResultAccepted) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode urlAuthResultAccepted#623a8fa0 as nil")
	}
	u.SetFlags()
	if err := u.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode urlAuthResultAccepted#623a8fa0: field flags: %w", err)
	}
	if u.Flags.Has(0) {
		b.PutString(u.URL)
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *URLAuthResultAccepted) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode urlAuthResultAccepted#623a8fa0 to nil")
	}
	if err := b.ConsumeID(URLAuthResultAcceptedTypeID); err != nil {
		return fmt.Errorf("unable to decode urlAuthResultAccepted#623a8fa0: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *URLAuthResultAccepted) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode urlAuthResultAccepted#623a8fa0 to nil")
	}
	{
		if err := u.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode urlAuthResultAccepted#623a8fa0: field flags: %w", err)
		}
	}
	if u.Flags.Has(0) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode urlAuthResultAccepted#623a8fa0: field url: %w", err)
		}
		u.URL = value
	}
	return nil
}

// SetURL sets value of URL conditional field.
func (u *URLAuthResultAccepted) SetURL(value string) {
	u.Flags.Set(0)
	u.URL = value
}

// GetURL returns value of URL conditional field and
// boolean which is true if field was set.
func (u *URLAuthResultAccepted) GetURL() (value string, ok bool) {
	if u == nil {
		return
	}
	if !u.Flags.Has(0) {
		return value, false
	}
	return u.URL, true
}

// URLAuthResultDefault represents TL type `urlAuthResultDefault#a9d6db1f`.
// Details about an accepted authorization request, for more info click here »¹
//
// Links:
//  1. https://core.telegram.org/api/url-authorization
//
// See https://core.telegram.org/constructor/urlAuthResultDefault for reference.
type URLAuthResultDefault struct {
}

// URLAuthResultDefaultTypeID is TL type id of URLAuthResultDefault.
const URLAuthResultDefaultTypeID = 0xa9d6db1f

// construct implements constructor of URLAuthResultClass.
func (u URLAuthResultDefault) construct() URLAuthResultClass { return &u }

// Ensuring interfaces in compile-time for URLAuthResultDefault.
var (
	_ bin.Encoder     = &URLAuthResultDefault{}
	_ bin.Decoder     = &URLAuthResultDefault{}
	_ bin.BareEncoder = &URLAuthResultDefault{}
	_ bin.BareDecoder = &URLAuthResultDefault{}

	_ URLAuthResultClass = &URLAuthResultDefault{}
)

func (u *URLAuthResultDefault) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

// String implements fmt.Stringer.
func (u *URLAuthResultDefault) String() string {
	if u == nil {
		return "URLAuthResultDefault(nil)"
	}
	type Alias URLAuthResultDefault
	return fmt.Sprintf("URLAuthResultDefault%+v", Alias(*u))
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*URLAuthResultDefault) TypeID() uint32 {
	return URLAuthResultDefaultTypeID
}

// TypeName returns name of type in TL schema.
func (*URLAuthResultDefault) TypeName() string {
	return "urlAuthResultDefault"
}

// TypeInfo returns info about TL type.
func (u *URLAuthResultDefault) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "urlAuthResultDefault",
		ID:   URLAuthResultDefaultTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *URLAuthResultDefault) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode urlAuthResultDefault#a9d6db1f as nil")
	}
	b.PutID(URLAuthResultDefaultTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *URLAuthResultDefault) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode urlAuthResultDefault#a9d6db1f as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *URLAuthResultDefault) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode urlAuthResultDefault#a9d6db1f to nil")
	}
	if err := b.ConsumeID(URLAuthResultDefaultTypeID); err != nil {
		return fmt.Errorf("unable to decode urlAuthResultDefault#a9d6db1f: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *URLAuthResultDefault) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode urlAuthResultDefault#a9d6db1f to nil")
	}
	return nil
}

// URLAuthResultClassName is schema name of URLAuthResultClass.
const URLAuthResultClassName = "UrlAuthResult"

// URLAuthResultClass represents UrlAuthResult generic type.
//
// See https://core.telegram.org/type/UrlAuthResult for reference.
//
// Example:
//
//	g, err := tg.DecodeURLAuthResult(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.URLAuthResultRequest: // urlAuthResultRequest#3cd623ec
//	case *tg.URLAuthResultAccepted: // urlAuthResultAccepted#623a8fa0
//	case *tg.URLAuthResultDefault: // urlAuthResultDefault#a9d6db1f
//	default: panic(v)
//	}
type URLAuthResultClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() URLAuthResultClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool
}

// DecodeURLAuthResult implements binary de-serialization for URLAuthResultClass.
func DecodeURLAuthResult(buf *bin.Buffer) (URLAuthResultClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case URLAuthResultRequestTypeID:
		// Decoding urlAuthResultRequest#3cd623ec.
		v := URLAuthResultRequest{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode URLAuthResultClass: %w", err)
		}
		return &v, nil
	case URLAuthResultAcceptedTypeID:
		// Decoding urlAuthResultAccepted#623a8fa0.
		v := URLAuthResultAccepted{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode URLAuthResultClass: %w", err)
		}
		return &v, nil
	case URLAuthResultDefaultTypeID:
		// Decoding urlAuthResultDefault#a9d6db1f.
		v := URLAuthResultDefault{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode URLAuthResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode URLAuthResultClass: %w", bin.NewUnexpectedID(id))
	}
}

// URLAuthResult boxes the URLAuthResultClass providing a helper.
type URLAuthResultBox struct {
	UrlAuthResult URLAuthResultClass
}

// Decode implements bin.Decoder for URLAuthResultBox.
func (b *URLAuthResultBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode URLAuthResultBox to nil")
	}
	v, err := DecodeURLAuthResult(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.UrlAuthResult = v
	return nil
}

// Encode implements bin.Encode for URLAuthResultBox.
func (b *URLAuthResultBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.UrlAuthResult == nil {
		return fmt.Errorf("unable to encode URLAuthResultClass as nil")
	}
	return b.UrlAuthResult.Encode(buf)
}
