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

// AuthBindTempAuthKeyRequest represents TL type `auth.bindTempAuthKey#cdd42a05`.
// Binds a temporary authorization key temp_auth_key_id to the permanent authorization
// key perm_auth_key_id. Each permanent key may only be bound to one temporary key at a
// time, binding a new temporary key overwrites the previous one.
// For more information, see Perfect Forward Secrecy¹.
//
// Links:
//  1. https://core.telegram.org/api/pfs
//
// See https://core.telegram.org/method/auth.bindTempAuthKey for reference.
type AuthBindTempAuthKeyRequest struct {
	// Permanent auth_key_id to bind to
	PermAuthKeyID int64
	// Random long from Binding message contents¹
	//
	// Links:
	//  1) https://core.telegram.org#binding-message-contents
	Nonce int64
	// Unix timestamp to invalidate temporary key, see Binding message contents¹
	//
	// Links:
	//  1) https://core.telegram.org#binding-message-contents
	ExpiresAt int
	// See Generating encrypted_message¹
	//
	// Links:
	//  1) https://core.telegram.org#generating-encrypted-message
	EncryptedMessage []byte
}

// AuthBindTempAuthKeyRequestTypeID is TL type id of AuthBindTempAuthKeyRequest.
const AuthBindTempAuthKeyRequestTypeID = 0xcdd42a05

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

func ( *AuthBindTempAuthKeyRequest) () bool {
	if  == nil {
		return true
	}
	if !(.PermAuthKeyID == 0) {
		return false
	}
	if !(.Nonce == 0) {
		return false
	}
	if !(.ExpiresAt == 0) {
		return false
	}
	if !(.EncryptedMessage == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AuthBindTempAuthKeyRequest from given interface.
func ( *AuthBindTempAuthKeyRequest) ( interface {
	() ( int64)
	() ( int64)
	() ( int)
	() ( []byte)
}) {
	.PermAuthKeyID = .()
	.Nonce = .()
	.ExpiresAt = .()
	.EncryptedMessage = .()
}

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

// TypeName returns name of type in TL schema.
func (*AuthBindTempAuthKeyRequest) () string {
	return "auth.bindTempAuthKey"
}

// TypeInfo returns info about TL type.
func ( *AuthBindTempAuthKeyRequest) () tdp.Type {
	 := tdp.Type{
		Name: "auth.bindTempAuthKey",
		ID:   AuthBindTempAuthKeyRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "PermAuthKeyID",
			SchemaName: "perm_auth_key_id",
		},
		{
			Name:       "Nonce",
			SchemaName: "nonce",
		},
		{
			Name:       "ExpiresAt",
			SchemaName: "expires_at",
		},
		{
			Name:       "EncryptedMessage",
			SchemaName: "encrypted_message",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *AuthBindTempAuthKeyRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode auth.bindTempAuthKey#cdd42a05 as nil")
	}
	.PutID(AuthBindTempAuthKeyRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AuthBindTempAuthKeyRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode auth.bindTempAuthKey#cdd42a05 as nil")
	}
	.PutLong(.PermAuthKeyID)
	.PutLong(.Nonce)
	.PutInt(.ExpiresAt)
	.PutBytes(.EncryptedMessage)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *AuthBindTempAuthKeyRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode auth.bindTempAuthKey#cdd42a05 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode auth.bindTempAuthKey#cdd42a05: field perm_auth_key_id: %w", )
		}
		.PermAuthKeyID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode auth.bindTempAuthKey#cdd42a05: field nonce: %w", )
		}
		.Nonce = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode auth.bindTempAuthKey#cdd42a05: field expires_at: %w", )
		}
		.ExpiresAt = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode auth.bindTempAuthKey#cdd42a05: field encrypted_message: %w", )
		}
		.EncryptedMessage = 
	}
	return nil
}

// GetPermAuthKeyID returns value of PermAuthKeyID field.
func ( *AuthBindTempAuthKeyRequest) () ( int64) {
	if  == nil {
		return
	}
	return .PermAuthKeyID
}

// GetNonce returns value of Nonce field.
func ( *AuthBindTempAuthKeyRequest) () ( int64) {
	if  == nil {
		return
	}
	return .Nonce
}

// GetExpiresAt returns value of ExpiresAt field.
func ( *AuthBindTempAuthKeyRequest) () ( int) {
	if  == nil {
		return
	}
	return .ExpiresAt
}

// GetEncryptedMessage returns value of EncryptedMessage field.
func ( *AuthBindTempAuthKeyRequest) () ( []byte) {
	if  == nil {
		return
	}
	return .EncryptedMessage
}

// AuthBindTempAuthKey invokes method auth.bindTempAuthKey#cdd42a05 returning error if any.
// Binds a temporary authorization key temp_auth_key_id to the permanent authorization
// key perm_auth_key_id. Each permanent key may only be bound to one temporary key at a
// time, binding a new temporary key overwrites the previous one.
// For more information, see Perfect Forward Secrecy¹.
//
// Links:
//  1. https://core.telegram.org/api/pfs
//
// Possible errors:
//
//	400 ENCRYPTED_MESSAGE_INVALID: Encrypted message invalid.
//	400 TEMP_AUTH_KEY_ALREADY_BOUND: The passed temporary key is already bound to another perm_auth_key_id.
//	400 TEMP_AUTH_KEY_EMPTY: No temporary auth key provided.
//
// See https://core.telegram.org/method/auth.bindTempAuthKey for reference.
// Can be used by bots.
func ( *Client) ( context.Context,  *AuthBindTempAuthKeyRequest) (bool, error) {
	var  BoolBox

	if  := .rpc.Invoke(, , &);  != nil {
		return false, 
	}
	,  := .Bool.(*BoolTrue)
	return , nil
}