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

// PhoneJoinGroupCallRequest represents TL type `phone.joinGroupCall#8fb53057`.
// Join a group call¹, see here »² for the full flow.
//
// Links:
//  1. https://core.telegram.org/api/group-calls
//  2. https://core.telegram.org/api/group-calls
//
// See https://core.telegram.org/method/phone.joinGroupCall for reference.
type PhoneJoinGroupCallRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the user will be muted by default upon joining.
	Muted bool
	// If set, the user's video will be disabled by default upon joining.
	VideoStopped bool
	// The group call
	Call InputGroupCallClass
	// Join the group call, presenting yourself as the specified user/channel
	JoinAs InputPeerClass
	// The invitation hash from the invite link »¹, if provided allows speaking in a
	// livestream or muted group chat.
	//
	// Links:
	//  1) https://core.telegram.org/api/links#video-chat-livestream-links
	//
	// Use SetInviteHash and GetInviteHash helpers.
	InviteHash string
	// For conference calls, your public key.
	//
	// Use SetPublicKey and GetPublicKey helpers.
	PublicKey bin.Int256
	// The block containing an appropriate e2e.chain.changeSetGroupState event¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/end-to-end/group-calls
	//
	// Use SetBlock and GetBlock helpers.
	Block []byte
	// WebRTC parameters
	Params DataJSON
}

// PhoneJoinGroupCallRequestTypeID is TL type id of PhoneJoinGroupCallRequest.
const PhoneJoinGroupCallRequestTypeID = 0x8fb53057

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

func ( *PhoneJoinGroupCallRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Muted == false) {
		return false
	}
	if !(.VideoStopped == false) {
		return false
	}
	if !(.Call == nil) {
		return false
	}
	if !(.JoinAs == nil) {
		return false
	}
	if !(.InviteHash == "") {
		return false
	}
	if !(.PublicKey == bin.Int256{}) {
		return false
	}
	if !(.Block == nil) {
		return false
	}
	if !(.Params.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneJoinGroupCallRequest from given interface.
func ( *PhoneJoinGroupCallRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( InputGroupCallClass)
	() ( InputPeerClass)
	() ( string,  bool)
	() ( bin.Int256,  bool)
	() ( []byte,  bool)
	() ( DataJSON)
}) {
	.Muted = .()
	.VideoStopped = .()
	.Call = .()
	.JoinAs = .()
	if ,  := .();  {
		.InviteHash = 
	}

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

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

	.Params = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PhoneJoinGroupCallRequest) () tdp.Type {
	 := tdp.Type{
		Name: "phone.joinGroupCall",
		ID:   PhoneJoinGroupCallRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Muted",
			SchemaName: "muted",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "VideoStopped",
			SchemaName: "video_stopped",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Call",
			SchemaName: "call",
		},
		{
			Name:       "JoinAs",
			SchemaName: "join_as",
		},
		{
			Name:       "InviteHash",
			SchemaName: "invite_hash",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "PublicKey",
			SchemaName: "public_key",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Block",
			SchemaName: "block",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Params",
			SchemaName: "params",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PhoneJoinGroupCallRequest) () {
	if !(.Muted == false) {
		.Flags.Set(0)
	}
	if !(.VideoStopped == false) {
		.Flags.Set(2)
	}
	if !(.InviteHash == "") {
		.Flags.Set(1)
	}
	if !(.PublicKey == bin.Int256{}) {
		.Flags.Set(3)
	}
	if !(.Block == nil) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *PhoneJoinGroupCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phone.joinGroupCall#8fb53057 as nil")
	}
	.PutID(PhoneJoinGroupCallRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PhoneJoinGroupCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phone.joinGroupCall#8fb53057 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.joinGroupCall#8fb53057: field flags: %w", )
	}
	if .Call == nil {
		return fmt.Errorf("unable to encode phone.joinGroupCall#8fb53057: field call is nil")
	}
	if  := .Call.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.joinGroupCall#8fb53057: field call: %w", )
	}
	if .JoinAs == nil {
		return fmt.Errorf("unable to encode phone.joinGroupCall#8fb53057: field join_as is nil")
	}
	if  := .JoinAs.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.joinGroupCall#8fb53057: field join_as: %w", )
	}
	if .Flags.Has(1) {
		.PutString(.InviteHash)
	}
	if .Flags.Has(3) {
		.PutInt256(.PublicKey)
	}
	if .Flags.Has(3) {
		.PutBytes(.Block)
	}
	if  := .Params.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.joinGroupCall#8fb53057: field params: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PhoneJoinGroupCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode phone.joinGroupCall#8fb53057 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode phone.joinGroupCall#8fb53057: field flags: %w", )
		}
	}
	.Muted = .Flags.Has(0)
	.VideoStopped = .Flags.Has(2)
	{
		,  := DecodeInputGroupCall()
		if  != nil {
			return fmt.Errorf("unable to decode phone.joinGroupCall#8fb53057: field call: %w", )
		}
		.Call = 
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode phone.joinGroupCall#8fb53057: field join_as: %w", )
		}
		.JoinAs = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode phone.joinGroupCall#8fb53057: field invite_hash: %w", )
		}
		.InviteHash = 
	}
	if .Flags.Has(3) {
		,  := .Int256()
		if  != nil {
			return fmt.Errorf("unable to decode phone.joinGroupCall#8fb53057: field public_key: %w", )
		}
		.PublicKey = 
	}
	if .Flags.Has(3) {
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode phone.joinGroupCall#8fb53057: field block: %w", )
		}
		.Block = 
	}
	{
		if  := .Params.Decode();  != nil {
			return fmt.Errorf("unable to decode phone.joinGroupCall#8fb53057: field params: %w", )
		}
	}
	return nil
}

// SetMuted sets value of Muted conditional field.
func ( *PhoneJoinGroupCallRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Muted = true
	} else {
		.Flags.Unset(0)
		.Muted = false
	}
}

// GetMuted returns value of Muted conditional field.
func ( *PhoneJoinGroupCallRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetVideoStopped sets value of VideoStopped conditional field.
func ( *PhoneJoinGroupCallRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.VideoStopped = true
	} else {
		.Flags.Unset(2)
		.VideoStopped = false
	}
}

// GetVideoStopped returns value of VideoStopped conditional field.
func ( *PhoneJoinGroupCallRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// GetCall returns value of Call field.
func ( *PhoneJoinGroupCallRequest) () ( InputGroupCallClass) {
	if  == nil {
		return
	}
	return .Call
}

// GetJoinAs returns value of JoinAs field.
func ( *PhoneJoinGroupCallRequest) () ( InputPeerClass) {
	if  == nil {
		return
	}
	return .JoinAs
}

// SetInviteHash sets value of InviteHash conditional field.
func ( *PhoneJoinGroupCallRequest) ( string) {
	.Flags.Set(1)
	.InviteHash = 
}

// GetInviteHash returns value of InviteHash conditional field and
// boolean which is true if field was set.
func ( *PhoneJoinGroupCallRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .InviteHash, true
}

// SetPublicKey sets value of PublicKey conditional field.
func ( *PhoneJoinGroupCallRequest) ( bin.Int256) {
	.Flags.Set(3)
	.PublicKey = 
}

// GetPublicKey returns value of PublicKey conditional field and
// boolean which is true if field was set.
func ( *PhoneJoinGroupCallRequest) () ( bin.Int256,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .PublicKey, true
}

// SetBlock sets value of Block conditional field.
func ( *PhoneJoinGroupCallRequest) ( []byte) {
	.Flags.Set(3)
	.Block = 
}

// GetBlock returns value of Block conditional field and
// boolean which is true if field was set.
func ( *PhoneJoinGroupCallRequest) () ( []byte,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Block, true
}

// GetParams returns value of Params field.
func ( *PhoneJoinGroupCallRequest) () ( DataJSON) {
	if  == nil {
		return
	}
	return .Params
}

// PhoneJoinGroupCall invokes method phone.joinGroupCall#8fb53057 returning error if any.
// Join a group call¹, see here »² for the full flow.
//
// Links:
//  1. https://core.telegram.org/api/group-calls
//  2. https://core.telegram.org/api/group-calls
//
// Possible errors:
//
//	400 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
//	403 CHAT_WRITE_FORBIDDEN: You can't write in this chat.
//	400 DATA_JSON_INVALID: The provided JSON data is invalid.
//	500 GROUPCALL_ADD_PARTICIPANTS_FAILED:
//	403 GROUPCALL_FORBIDDEN: The group call has already ended.
//	400 GROUPCALL_INVALID: The specified group call is invalid.
//	400 GROUPCALL_SSRC_DUPLICATE_MUCH: The app needs to retry joining the group call with a new SSRC value.
//	400 JOIN_AS_PEER_INVALID: The specified peer cannot be used to join a group call.
//
// See https://core.telegram.org/method/phone.joinGroupCall for reference.
func ( *Client) ( context.Context,  *PhoneJoinGroupCallRequest) (UpdatesClass, error) {
	var  UpdatesBox

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