// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

// 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#92d33a0e`.
// 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
	// 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
}

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

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

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

	_ URLAuthResultClass = &URLAuthResultRequest{}
)

func ( *URLAuthResultRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.RequestWriteAccess == false) {
		return false
	}
	if !(.Bot == nil) {
		return false
	}
	if !(.Domain == "") {
		return false
	}

	return true
}

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

// FillFrom fills URLAuthResultRequest from given interface.
func ( *URLAuthResultRequest) ( interface {
	() ( bool)
	() ( UserClass)
	() ( string)
}) {
	.RequestWriteAccess = .()
	.Bot = .()
	.Domain = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *URLAuthResultRequest) () tdp.Type {
	 := tdp.Type{
		Name: "urlAuthResultRequest",
		ID:   URLAuthResultRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "RequestWriteAccess",
			SchemaName: "request_write_access",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
		{
			Name:       "Domain",
			SchemaName: "domain",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *URLAuthResultRequest) () {
	if !(.RequestWriteAccess == false) {
		.Flags.Set(0)
	}
}

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

// EncodeBare implements bin.BareEncoder.
func ( *URLAuthResultRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode urlAuthResultRequest#92d33a0e as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode urlAuthResultRequest#92d33a0e: field flags: %w", )
	}
	if .Bot == nil {
		return fmt.Errorf("unable to encode urlAuthResultRequest#92d33a0e: field bot is nil")
	}
	if  := .Bot.Encode();  != nil {
		return fmt.Errorf("unable to encode urlAuthResultRequest#92d33a0e: field bot: %w", )
	}
	.PutString(.Domain)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *URLAuthResultRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode urlAuthResultRequest#92d33a0e to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#92d33a0e: field flags: %w", )
		}
	}
	.RequestWriteAccess = .Flags.Has(0)
	{
		,  := DecodeUser()
		if  != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#92d33a0e: field bot: %w", )
		}
		.Bot = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode urlAuthResultRequest#92d33a0e: field domain: %w", )
		}
		.Domain = 
	}
	return nil
}

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

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

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

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

// URLAuthResultAccepted represents TL type `urlAuthResultAccepted#8f8c0e4e`.
// 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 {
	// The URL name of the website on which the user has logged in.
	URL string
}

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

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

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

	_ URLAuthResultClass = &URLAuthResultAccepted{}
)

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

	return true
}

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

// FillFrom fills URLAuthResultAccepted from given interface.
func ( *URLAuthResultAccepted) ( interface {
	() ( string)
}) {
	.URL = .()
}

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

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

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

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

// EncodeBare implements bin.BareEncoder.
func ( *URLAuthResultAccepted) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode urlAuthResultAccepted#8f8c0e4e as nil")
	}
	.PutString(.URL)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *URLAuthResultAccepted) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode urlAuthResultAccepted#8f8c0e4e to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode urlAuthResultAccepted#8f8c0e4e: field url: %w", )
		}
		.URL = 
	}
	return nil
}

// GetURL returns value of URL field.
func ( *URLAuthResultAccepted) () ( string) {
	if  == nil {
		return
	}
	return .URL
}

// 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 ( URLAuthResultDefault) () URLAuthResultClass { return & }

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

	_ URLAuthResultClass = &URLAuthResultDefault{}
)

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

	return true
}

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

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

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

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

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

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

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

// DecodeBare implements bin.BareDecoder.
func ( *URLAuthResultDefault) ( *bin.Buffer) error {
	if  == 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#92d33a0e
//	case *tg.URLAuthResultAccepted: // urlAuthResultAccepted#8f8c0e4e
//	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 ( *bin.Buffer) (URLAuthResultClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case URLAuthResultRequestTypeID:
		// Decoding urlAuthResultRequest#92d33a0e.
		 := URLAuthResultRequest{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode URLAuthResultClass: %w", )
		}
		return &, nil
	case URLAuthResultAcceptedTypeID:
		// Decoding urlAuthResultAccepted#8f8c0e4e.
		 := URLAuthResultAccepted{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode URLAuthResultClass: %w", )
		}
		return &, nil
	case URLAuthResultDefaultTypeID:
		// Decoding urlAuthResultDefault#a9d6db1f.
		 := URLAuthResultDefault{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode URLAuthResultClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode URLAuthResultClass: %w", bin.NewUnexpectedID())
	}
}

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

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

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