// 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{}
)

// MessagesAcceptURLAuthRequest represents TL type `messages.acceptUrlAuth#b12c7125`.
// Use this to accept a Seamless Telegram Login authorization request, for more info
// click here »¹
//
// Links:
//  1. https://core.telegram.org/api/url-authorization
//
// See https://core.telegram.org/method/messages.acceptUrlAuth for reference.
type MessagesAcceptURLAuthRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Set this flag to allow the bot to send messages to you (if requested)
	WriteAllowed bool
	// The location of the message
	//
	// Use SetPeer and GetPeer helpers.
	Peer InputPeerClass
	// Message ID of the message with the login button
	//
	// Use SetMsgID and GetMsgID helpers.
	MsgID int
	// ID of the login button
	//
	// Use SetButtonID and GetButtonID helpers.
	ButtonID int
	// URL used for link URL authorization, click here for more info »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/url-authorization#link-url-authorization
	//
	// Use SetURL and GetURL helpers.
	URL string
}

// MessagesAcceptURLAuthRequestTypeID is TL type id of MessagesAcceptURLAuthRequest.
const MessagesAcceptURLAuthRequestTypeID = 0xb12c7125

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

func ( *MessagesAcceptURLAuthRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.WriteAllowed == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.MsgID == 0) {
		return false
	}
	if !(.ButtonID == 0) {
		return false
	}
	if !(.URL == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesAcceptURLAuthRequest from given interface.
func ( *MessagesAcceptURLAuthRequest) ( interface {
	() ( bool)
	() ( InputPeerClass,  bool)
	() ( int,  bool)
	() ( int,  bool)
	() ( string,  bool)
}) {
	.WriteAllowed = .()
	if ,  := .();  {
		.Peer = 
	}

	if ,  := .();  {
		.MsgID = 
	}

	if ,  := .();  {
		.ButtonID = 
	}

	if ,  := .();  {
		.URL = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*MessagesAcceptURLAuthRequest) () string {
	return "messages.acceptUrlAuth"
}

// TypeInfo returns info about TL type.
func ( *MessagesAcceptURLAuthRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.acceptUrlAuth",
		ID:   MessagesAcceptURLAuthRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "WriteAllowed",
			SchemaName: "write_allowed",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "MsgID",
			SchemaName: "msg_id",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ButtonID",
			SchemaName: "button_id",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "URL",
			SchemaName: "url",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesAcceptURLAuthRequest) () {
	if !(.WriteAllowed == false) {
		.Flags.Set(0)
	}
	if !(.Peer == nil) {
		.Flags.Set(1)
	}
	if !(.MsgID == 0) {
		.Flags.Set(1)
	}
	if !(.ButtonID == 0) {
		.Flags.Set(1)
	}
	if !(.URL == "") {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesAcceptURLAuthRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.acceptUrlAuth#b12c7125 as nil")
	}
	.PutID(MessagesAcceptURLAuthRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesAcceptURLAuthRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.acceptUrlAuth#b12c7125 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.acceptUrlAuth#b12c7125: field flags: %w", )
	}
	if .Flags.Has(1) {
		if .Peer == nil {
			return fmt.Errorf("unable to encode messages.acceptUrlAuth#b12c7125: field peer is nil")
		}
		if  := .Peer.Encode();  != nil {
			return fmt.Errorf("unable to encode messages.acceptUrlAuth#b12c7125: field peer: %w", )
		}
	}
	if .Flags.Has(1) {
		.PutInt(.MsgID)
	}
	if .Flags.Has(1) {
		.PutInt(.ButtonID)
	}
	if .Flags.Has(2) {
		.PutString(.URL)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesAcceptURLAuthRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.acceptUrlAuth#b12c7125 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.acceptUrlAuth#b12c7125: field flags: %w", )
		}
	}
	.WriteAllowed = .Flags.Has(0)
	if .Flags.Has(1) {
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.acceptUrlAuth#b12c7125: field peer: %w", )
		}
		.Peer = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.acceptUrlAuth#b12c7125: field msg_id: %w", )
		}
		.MsgID = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.acceptUrlAuth#b12c7125: field button_id: %w", )
		}
		.ButtonID = 
	}
	if .Flags.Has(2) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.acceptUrlAuth#b12c7125: field url: %w", )
		}
		.URL = 
	}
	return nil
}

// SetWriteAllowed sets value of WriteAllowed conditional field.
func ( *MessagesAcceptURLAuthRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.WriteAllowed = true
	} else {
		.Flags.Unset(0)
		.WriteAllowed = false
	}
}

// GetWriteAllowed returns value of WriteAllowed conditional field.
func ( *MessagesAcceptURLAuthRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetPeer sets value of Peer conditional field.
func ( *MessagesAcceptURLAuthRequest) ( InputPeerClass) {
	.Flags.Set(1)
	.Peer = 
}

// GetPeer returns value of Peer conditional field and
// boolean which is true if field was set.
func ( *MessagesAcceptURLAuthRequest) () ( InputPeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Peer, true
}

// SetMsgID sets value of MsgID conditional field.
func ( *MessagesAcceptURLAuthRequest) ( int) {
	.Flags.Set(1)
	.MsgID = 
}

// GetMsgID returns value of MsgID conditional field and
// boolean which is true if field was set.
func ( *MessagesAcceptURLAuthRequest) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .MsgID, true
}

// SetButtonID sets value of ButtonID conditional field.
func ( *MessagesAcceptURLAuthRequest) ( int) {
	.Flags.Set(1)
	.ButtonID = 
}

// GetButtonID returns value of ButtonID conditional field and
// boolean which is true if field was set.
func ( *MessagesAcceptURLAuthRequest) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .ButtonID, true
}

// SetURL sets value of URL conditional field.
func ( *MessagesAcceptURLAuthRequest) ( string) {
	.Flags.Set(2)
	.URL = 
}

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

// MessagesAcceptURLAuth invokes method messages.acceptUrlAuth#b12c7125 returning error if any.
// Use this to accept a Seamless Telegram Login authorization request, for more info
// click here »¹
//
// Links:
//  1. https://core.telegram.org/api/url-authorization
//
// See https://core.telegram.org/method/messages.acceptUrlAuth for reference.
func ( *Client) ( context.Context,  *MessagesAcceptURLAuthRequest) (URLAuthResultClass, error) {
	var  URLAuthResultBox

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return .UrlAuthResult, nil
}