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

// ChannelsSetDiscussionGroupRequest represents TL type `channels.setDiscussionGroup#40582bb2`.
// Associate a group to a channel as discussion group¹ for that channel
//
// Links:
//  1. https://core.telegram.org/api/discussion
//
// See https://core.telegram.org/method/channels.setDiscussionGroup for reference.
type ChannelsSetDiscussionGroupRequest struct {
	// Channel
	Broadcast InputChannelClass
	// Discussion group¹ to associate to the channel
	//
	// Links:
	//  1) https://core.telegram.org/api/discussion
	Group InputChannelClass
}

// ChannelsSetDiscussionGroupRequestTypeID is TL type id of ChannelsSetDiscussionGroupRequest.
const ChannelsSetDiscussionGroupRequestTypeID = 0x40582bb2

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

func ( *ChannelsSetDiscussionGroupRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Broadcast == nil) {
		return false
	}
	if !(.Group == nil) {
		return false
	}

	return true
}

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

// FillFrom fills ChannelsSetDiscussionGroupRequest from given interface.
func ( *ChannelsSetDiscussionGroupRequest) ( interface {
	() ( InputChannelClass)
	() ( InputChannelClass)
}) {
	.Broadcast = .()
	.Group = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *ChannelsSetDiscussionGroupRequest) () tdp.Type {
	 := tdp.Type{
		Name: "channels.setDiscussionGroup",
		ID:   ChannelsSetDiscussionGroupRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Broadcast",
			SchemaName: "broadcast",
		},
		{
			Name:       "Group",
			SchemaName: "group",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ChannelsSetDiscussionGroupRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channels.setDiscussionGroup#40582bb2 as nil")
	}
	.PutID(ChannelsSetDiscussionGroupRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChannelsSetDiscussionGroupRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channels.setDiscussionGroup#40582bb2 as nil")
	}
	if .Broadcast == nil {
		return fmt.Errorf("unable to encode channels.setDiscussionGroup#40582bb2: field broadcast is nil")
	}
	if  := .Broadcast.Encode();  != nil {
		return fmt.Errorf("unable to encode channels.setDiscussionGroup#40582bb2: field broadcast: %w", )
	}
	if .Group == nil {
		return fmt.Errorf("unable to encode channels.setDiscussionGroup#40582bb2: field group is nil")
	}
	if  := .Group.Encode();  != nil {
		return fmt.Errorf("unable to encode channels.setDiscussionGroup#40582bb2: field group: %w", )
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ChannelsSetDiscussionGroupRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channels.setDiscussionGroup#40582bb2 to nil")
	}
	if  := .ConsumeID(ChannelsSetDiscussionGroupRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode channels.setDiscussionGroup#40582bb2: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChannelsSetDiscussionGroupRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channels.setDiscussionGroup#40582bb2 to nil")
	}
	{
		,  := DecodeInputChannel()
		if  != nil {
			return fmt.Errorf("unable to decode channels.setDiscussionGroup#40582bb2: field broadcast: %w", )
		}
		.Broadcast = 
	}
	{
		,  := DecodeInputChannel()
		if  != nil {
			return fmt.Errorf("unable to decode channels.setDiscussionGroup#40582bb2: field group: %w", )
		}
		.Group = 
	}
	return nil
}

// GetBroadcast returns value of Broadcast field.
func ( *ChannelsSetDiscussionGroupRequest) () ( InputChannelClass) {
	if  == nil {
		return
	}
	return .Broadcast
}

// GetGroup returns value of Group field.
func ( *ChannelsSetDiscussionGroupRequest) () ( InputChannelClass) {
	if  == nil {
		return
	}
	return .Group
}

// GetBroadcastAsNotEmpty returns mapped value of Broadcast field.
func ( *ChannelsSetDiscussionGroupRequest) () (NotEmptyInputChannel, bool) {
	return .Broadcast.AsNotEmpty()
}

// GetGroupAsNotEmpty returns mapped value of Group field.
func ( *ChannelsSetDiscussionGroupRequest) () (NotEmptyInputChannel, bool) {
	return .Group.AsNotEmpty()
}

// ChannelsSetDiscussionGroup invokes method channels.setDiscussionGroup#40582bb2 returning error if any.
// Associate a group to a channel as discussion group¹ for that channel
//
// Links:
//  1. https://core.telegram.org/api/discussion
//
// Possible errors:
//
//	400 BROADCAST_ID_INVALID: Broadcast ID invalid.
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	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 LINK_NOT_MODIFIED: Discussion link not modified.
//	400 MEGAGROUP_ID_INVALID: Invalid supergroup ID.
//	400 MEGAGROUP_PREHISTORY_HIDDEN: Group with hidden history for new members can't be set as discussion groups.
//
// See https://core.telegram.org/method/channels.setDiscussionGroup for reference.
func ( *Client) ( context.Context,  *ChannelsSetDiscussionGroupRequest) (bool, error) {
	var  BoolBox

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