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

// MessagesRequestEncryptionRequest represents TL type `messages.requestEncryption#f64daf43`.
// Sends a request to start a secret chat to the user.
//
// See https://core.telegram.org/method/messages.requestEncryption for reference.
type MessagesRequestEncryptionRequest struct {
	// User ID
	UserID InputUserClass
	// Unique client request ID required to prevent resending. This also doubles as the chat
	// ID.
	RandomID int
	// A = g ^ a mod p, see Wikipedia¹
	//
	// Links:
	//  1) https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
	GA []byte
}

// MessagesRequestEncryptionRequestTypeID is TL type id of MessagesRequestEncryptionRequest.
const MessagesRequestEncryptionRequestTypeID = 0xf64daf43

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

func ( *MessagesRequestEncryptionRequest) () bool {
	if  == nil {
		return true
	}
	if !(.UserID == nil) {
		return false
	}
	if !(.RandomID == 0) {
		return false
	}
	if !(.GA == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesRequestEncryptionRequest from given interface.
func ( *MessagesRequestEncryptionRequest) ( interface {
	() ( InputUserClass)
	() ( int)
	() ( []byte)
}) {
	.UserID = .()
	.RandomID = .()
	.GA = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesRequestEncryptionRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.requestEncryption",
		ID:   MessagesRequestEncryptionRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "GA",
			SchemaName: "g_a",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *MessagesRequestEncryptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.requestEncryption#f64daf43 as nil")
	}
	.PutID(MessagesRequestEncryptionRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesRequestEncryptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.requestEncryption#f64daf43 as nil")
	}
	if .UserID == nil {
		return fmt.Errorf("unable to encode messages.requestEncryption#f64daf43: field user_id is nil")
	}
	if  := .UserID.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.requestEncryption#f64daf43: field user_id: %w", )
	}
	.PutInt(.RandomID)
	.PutBytes(.GA)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesRequestEncryptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.requestEncryption#f64daf43 to nil")
	}
	{
		,  := DecodeInputUser()
		if  != nil {
			return fmt.Errorf("unable to decode messages.requestEncryption#f64daf43: field user_id: %w", )
		}
		.UserID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.requestEncryption#f64daf43: field random_id: %w", )
		}
		.RandomID = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode messages.requestEncryption#f64daf43: field g_a: %w", )
		}
		.GA = 
	}
	return nil
}

// GetUserID returns value of UserID field.
func ( *MessagesRequestEncryptionRequest) () ( InputUserClass) {
	if  == nil {
		return
	}
	return .UserID
}

// GetRandomID returns value of RandomID field.
func ( *MessagesRequestEncryptionRequest) () ( int) {
	if  == nil {
		return
	}
	return .RandomID
}

// GetGA returns value of GA field.
func ( *MessagesRequestEncryptionRequest) () ( []byte) {
	if  == nil {
		return
	}
	return .GA
}

// MessagesRequestEncryption invokes method messages.requestEncryption#f64daf43 returning error if any.
// Sends a request to start a secret chat to the user.
//
// Possible errors:
//
//	400 DH_G_A_INVALID: g_a invalid.
//	400 INPUT_USER_DEACTIVATED: The specified user was deleted.
//	400 USER_ID_INVALID: The provided user ID is invalid.
//
// See https://core.telegram.org/method/messages.requestEncryption for reference.
func ( *Client) ( context.Context,  *MessagesRequestEncryptionRequest) (EncryptedChatClass, error) {
	var  EncryptedChatBox

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