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

// PhoneRequestCallRequest represents TL type `phone.requestCall#42ff96ed`.
// Start a telegram phone call
//
// See https://core.telegram.org/method/phone.requestCall for reference.
type PhoneRequestCallRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether to start a video call
	Video bool
	// Destination of the phone call
	UserID InputUserClass
	// Random ID to avoid resending the same object
	RandomID int
	// Parameter for E2E encryption key exchange »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/end-to-end/voice-calls
	GAHash []byte
	// Phone call settings
	Protocol PhoneCallProtocol
}

// PhoneRequestCallRequestTypeID is TL type id of PhoneRequestCallRequest.
const PhoneRequestCallRequestTypeID = 0x42ff96ed

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

func ( *PhoneRequestCallRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Video == false) {
		return false
	}
	if !(.UserID == nil) {
		return false
	}
	if !(.RandomID == 0) {
		return false
	}
	if !(.GAHash == nil) {
		return false
	}
	if !(.Protocol.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneRequestCallRequest from given interface.
func ( *PhoneRequestCallRequest) ( interface {
	() ( bool)
	() ( InputUserClass)
	() ( int)
	() ( []byte)
	() ( PhoneCallProtocol)
}) {
	.Video = .()
	.UserID = .()
	.RandomID = .()
	.GAHash = .()
	.Protocol = .()
}

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

// TypeName returns name of type in TL schema.
func (*PhoneRequestCallRequest) () string {
	return "phone.requestCall"
}

// TypeInfo returns info about TL type.
func ( *PhoneRequestCallRequest) () tdp.Type {
	 := tdp.Type{
		Name: "phone.requestCall",
		ID:   PhoneRequestCallRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Video",
			SchemaName: "video",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "GAHash",
			SchemaName: "g_a_hash",
		},
		{
			Name:       "Protocol",
			SchemaName: "protocol",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PhoneRequestCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phone.requestCall#42ff96ed as nil")
	}
	.PutID(PhoneRequestCallRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PhoneRequestCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phone.requestCall#42ff96ed as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.requestCall#42ff96ed: field flags: %w", )
	}
	if .UserID == nil {
		return fmt.Errorf("unable to encode phone.requestCall#42ff96ed: field user_id is nil")
	}
	if  := .UserID.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.requestCall#42ff96ed: field user_id: %w", )
	}
	.PutInt(.RandomID)
	.PutBytes(.GAHash)
	if  := .Protocol.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.requestCall#42ff96ed: field protocol: %w", )
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PhoneRequestCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode phone.requestCall#42ff96ed to nil")
	}
	if  := .ConsumeID(PhoneRequestCallRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode phone.requestCall#42ff96ed: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PhoneRequestCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode phone.requestCall#42ff96ed to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode phone.requestCall#42ff96ed: field flags: %w", )
		}
	}
	.Video = .Flags.Has(0)
	{
		,  := DecodeInputUser()
		if  != nil {
			return fmt.Errorf("unable to decode phone.requestCall#42ff96ed: field user_id: %w", )
		}
		.UserID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode phone.requestCall#42ff96ed: field random_id: %w", )
		}
		.RandomID = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode phone.requestCall#42ff96ed: field g_a_hash: %w", )
		}
		.GAHash = 
	}
	{
		if  := .Protocol.Decode();  != nil {
			return fmt.Errorf("unable to decode phone.requestCall#42ff96ed: field protocol: %w", )
		}
	}
	return nil
}

// SetVideo sets value of Video conditional field.
func ( *PhoneRequestCallRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Video = true
	} else {
		.Flags.Unset(0)
		.Video = false
	}
}

// GetVideo returns value of Video conditional field.
func ( *PhoneRequestCallRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

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

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

// GetGAHash returns value of GAHash field.
func ( *PhoneRequestCallRequest) () ( []byte) {
	if  == nil {
		return
	}
	return .GAHash
}

// GetProtocol returns value of Protocol field.
func ( *PhoneRequestCallRequest) () ( PhoneCallProtocol) {
	if  == nil {
		return
	}
	return .Protocol
}

// PhoneRequestCall invokes method phone.requestCall#42ff96ed returning error if any.
// Start a telegram phone call
//
// Possible errors:
//
//	400 CALL_PROTOCOL_FLAGS_INVALID: Call protocol flags invalid.
//	400 INPUT_USER_DEACTIVATED: The specified user was deleted.
//	400 PARTICIPANT_VERSION_OUTDATED: The other participant does not use an up to date telegram client with support for calls.
//	400 USER_ID_INVALID: The provided user ID is invalid.
//	403 USER_IS_BLOCKED: You were blocked by this user.
//	403 USER_PRIVACY_RESTRICTED: The user's privacy settings do not allow you to do this.
//
// See https://core.telegram.org/method/phone.requestCall for reference.
func ( *Client) ( context.Context,  *PhoneRequestCallRequest) (*PhonePhoneCall, error) {
	var  PhonePhoneCall

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