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

// ChannelsToggleJoinRequestRequest represents TL type `channels.toggleJoinRequest#4c2985b6`.
// Set whether all users should request admin approval to join the group »¹.
//
// Links:
//  1. https://core.telegram.org/api/invites#join-requests
//
// See https://core.telegram.org/method/channels.toggleJoinRequest for reference.
type ChannelsToggleJoinRequestRequest struct {
	// Group
	Channel InputChannelClass
	// Toggle
	Enabled bool
}

// ChannelsToggleJoinRequestRequestTypeID is TL type id of ChannelsToggleJoinRequestRequest.
const ChannelsToggleJoinRequestRequestTypeID = 0x4c2985b6

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

func ( *ChannelsToggleJoinRequestRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Channel == nil) {
		return false
	}
	if !(.Enabled == false) {
		return false
	}

	return true
}

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

// FillFrom fills ChannelsToggleJoinRequestRequest from given interface.
func ( *ChannelsToggleJoinRequestRequest) ( interface {
	() ( InputChannelClass)
	() ( bool)
}) {
	.Channel = .()
	.Enabled = .()
}

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

// TypeName returns name of type in TL schema.
func (*ChannelsToggleJoinRequestRequest) () string {
	return "channels.toggleJoinRequest"
}

// TypeInfo returns info about TL type.
func ( *ChannelsToggleJoinRequestRequest) () tdp.Type {
	 := tdp.Type{
		Name: "channels.toggleJoinRequest",
		ID:   ChannelsToggleJoinRequestRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Channel",
			SchemaName: "channel",
		},
		{
			Name:       "Enabled",
			SchemaName: "enabled",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ChannelsToggleJoinRequestRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channels.toggleJoinRequest#4c2985b6 as nil")
	}
	.PutID(ChannelsToggleJoinRequestRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChannelsToggleJoinRequestRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channels.toggleJoinRequest#4c2985b6 as nil")
	}
	if .Channel == nil {
		return fmt.Errorf("unable to encode channels.toggleJoinRequest#4c2985b6: field channel is nil")
	}
	if  := .Channel.Encode();  != nil {
		return fmt.Errorf("unable to encode channels.toggleJoinRequest#4c2985b6: field channel: %w", )
	}
	.PutBool(.Enabled)
	return nil
}

// Decode implements bin.Decoder.
func ( *ChannelsToggleJoinRequestRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channels.toggleJoinRequest#4c2985b6 to nil")
	}
	if  := .ConsumeID(ChannelsToggleJoinRequestRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode channels.toggleJoinRequest#4c2985b6: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChannelsToggleJoinRequestRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channels.toggleJoinRequest#4c2985b6 to nil")
	}
	{
		,  := DecodeInputChannel()
		if  != nil {
			return fmt.Errorf("unable to decode channels.toggleJoinRequest#4c2985b6: field channel: %w", )
		}
		.Channel = 
	}
	{
		,  := .Bool()
		if  != nil {
			return fmt.Errorf("unable to decode channels.toggleJoinRequest#4c2985b6: field enabled: %w", )
		}
		.Enabled = 
	}
	return nil
}

// GetChannel returns value of Channel field.
func ( *ChannelsToggleJoinRequestRequest) () ( InputChannelClass) {
	if  == nil {
		return
	}
	return .Channel
}

// GetEnabled returns value of Enabled field.
func ( *ChannelsToggleJoinRequestRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Enabled
}

// GetChannelAsNotEmpty returns mapped value of Channel field.
func ( *ChannelsToggleJoinRequestRequest) () (NotEmptyInputChannel, bool) {
	return .Channel.AsNotEmpty()
}

// ChannelsToggleJoinRequest invokes method channels.toggleJoinRequest#4c2985b6 returning error if any.
// Set whether all users should request admin approval to join the group »¹.
//
// Links:
//  1. https://core.telegram.org/api/invites#join-requests
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	400 CHAT_ID_INVALID: The provided chat id is invalid.
//	400 CHAT_NOT_MODIFIED: No changes were made to chat information because the new information you passed is identical to the current information.
//	400 CHAT_PUBLIC_REQUIRED: You can only enable join requests in public groups.
//
// See https://core.telegram.org/method/channels.toggleJoinRequest for reference.
func ( *Client) ( context.Context,  *ChannelsToggleJoinRequestRequest) (UpdatesClass, error) {
	var  UpdatesBox

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