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

// ChatParticipantsForbidden represents TL type `chatParticipantsForbidden#8763d3e1`.
// Info on members is unavailable
//
// See https://core.telegram.org/constructor/chatParticipantsForbidden for reference.
type ChatParticipantsForbidden struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Group ID
	ChatID int64
	// Info about the group membership of the current user
	//
	// Use SetSelfParticipant and GetSelfParticipant helpers.
	SelfParticipant ChatParticipantClass
}

// ChatParticipantsForbiddenTypeID is TL type id of ChatParticipantsForbidden.
const ChatParticipantsForbiddenTypeID = 0x8763d3e1

// construct implements constructor of ChatParticipantsClass.
func ( ChatParticipantsForbidden) () ChatParticipantsClass { return & }

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

	_ ChatParticipantsClass = &ChatParticipantsForbidden{}
)

func ( *ChatParticipantsForbidden) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.ChatID == 0) {
		return false
	}
	if !(.SelfParticipant == nil) {
		return false
	}

	return true
}

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

// FillFrom fills ChatParticipantsForbidden from given interface.
func ( *ChatParticipantsForbidden) ( interface {
	() ( int64)
	() ( ChatParticipantClass,  bool)
}) {
	.ChatID = .()
	if ,  := .();  {
		.SelfParticipant = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*ChatParticipantsForbidden) () string {
	return "chatParticipantsForbidden"
}

// TypeInfo returns info about TL type.
func ( *ChatParticipantsForbidden) () tdp.Type {
	 := tdp.Type{
		Name: "chatParticipantsForbidden",
		ID:   ChatParticipantsForbiddenTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "SelfParticipant",
			SchemaName: "self_participant",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *ChatParticipantsForbidden) () {
	if !(.SelfParticipant == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *ChatParticipantsForbidden) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipantsForbidden#8763d3e1 as nil")
	}
	.PutID(ChatParticipantsForbiddenTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChatParticipantsForbidden) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipantsForbidden#8763d3e1 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode chatParticipantsForbidden#8763d3e1: field flags: %w", )
	}
	.PutLong(.ChatID)
	if .Flags.Has(0) {
		if .SelfParticipant == nil {
			return fmt.Errorf("unable to encode chatParticipantsForbidden#8763d3e1: field self_participant is nil")
		}
		if  := .SelfParticipant.Encode();  != nil {
			return fmt.Errorf("unable to encode chatParticipantsForbidden#8763d3e1: field self_participant: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ChatParticipantsForbidden) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipantsForbidden#8763d3e1 to nil")
	}
	if  := .ConsumeID(ChatParticipantsForbiddenTypeID);  != nil {
		return fmt.Errorf("unable to decode chatParticipantsForbidden#8763d3e1: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChatParticipantsForbidden) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipantsForbidden#8763d3e1 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode chatParticipantsForbidden#8763d3e1: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipantsForbidden#8763d3e1: field chat_id: %w", )
		}
		.ChatID = 
	}
	if .Flags.Has(0) {
		,  := DecodeChatParticipant()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipantsForbidden#8763d3e1: field self_participant: %w", )
		}
		.SelfParticipant = 
	}
	return nil
}

// GetChatID returns value of ChatID field.
func ( *ChatParticipantsForbidden) () ( int64) {
	if  == nil {
		return
	}
	return .ChatID
}

// SetSelfParticipant sets value of SelfParticipant conditional field.
func ( *ChatParticipantsForbidden) ( ChatParticipantClass) {
	.Flags.Set(0)
	.SelfParticipant = 
}

// GetSelfParticipant returns value of SelfParticipant conditional field and
// boolean which is true if field was set.
func ( *ChatParticipantsForbidden) () ( ChatParticipantClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .SelfParticipant, true
}

// ChatParticipants represents TL type `chatParticipants#3cbc93f8`.
// Group members.
//
// See https://core.telegram.org/constructor/chatParticipants for reference.
type ChatParticipants struct {
	// Group identifier
	ChatID int64
	// List of group members
	Participants []ChatParticipantClass
	// Group version number
	Version int
}

// ChatParticipantsTypeID is TL type id of ChatParticipants.
const ChatParticipantsTypeID = 0x3cbc93f8

// construct implements constructor of ChatParticipantsClass.
func ( ChatParticipants) () ChatParticipantsClass { return & }

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

	_ ChatParticipantsClass = &ChatParticipants{}
)

func ( *ChatParticipants) () bool {
	if  == nil {
		return true
	}
	if !(.ChatID == 0) {
		return false
	}
	if !(.Participants == nil) {
		return false
	}
	if !(.Version == 0) {
		return false
	}

	return true
}

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

// FillFrom fills ChatParticipants from given interface.
func ( *ChatParticipants) ( interface {
	() ( int64)
	() ( []ChatParticipantClass)
	() ( int)
}) {
	.ChatID = .()
	.Participants = .()
	.Version = .()
}

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

// TypeName returns name of type in TL schema.
func (*ChatParticipants) () string {
	return "chatParticipants"
}

// TypeInfo returns info about TL type.
func ( *ChatParticipants) () tdp.Type {
	 := tdp.Type{
		Name: "chatParticipants",
		ID:   ChatParticipantsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "Participants",
			SchemaName: "participants",
		},
		{
			Name:       "Version",
			SchemaName: "version",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ChatParticipants) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipants#3cbc93f8 as nil")
	}
	.PutID(ChatParticipantsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChatParticipants) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipants#3cbc93f8 as nil")
	}
	.PutLong(.ChatID)
	.PutVectorHeader(len(.Participants))
	for ,  := range .Participants {
		if  == nil {
			return fmt.Errorf("unable to encode chatParticipants#3cbc93f8: field participants element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode chatParticipants#3cbc93f8: field participants element with index %d: %w", , )
		}
	}
	.PutInt(.Version)
	return nil
}

// Decode implements bin.Decoder.
func ( *ChatParticipants) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipants#3cbc93f8 to nil")
	}
	if  := .ConsumeID(ChatParticipantsTypeID);  != nil {
		return fmt.Errorf("unable to decode chatParticipants#3cbc93f8: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChatParticipants) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipants#3cbc93f8 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipants#3cbc93f8: field chat_id: %w", )
		}
		.ChatID = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipants#3cbc93f8: field participants: %w", )
		}

		if  > 0 {
			.Participants = make([]ChatParticipantClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChatParticipant()
			if  != nil {
				return fmt.Errorf("unable to decode chatParticipants#3cbc93f8: field participants: %w", )
			}
			.Participants = append(.Participants, )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipants#3cbc93f8: field version: %w", )
		}
		.Version = 
	}
	return nil
}

// GetChatID returns value of ChatID field.
func ( *ChatParticipants) () ( int64) {
	if  == nil {
		return
	}
	return .ChatID
}

// GetParticipants returns value of Participants field.
func ( *ChatParticipants) () ( []ChatParticipantClass) {
	if  == nil {
		return
	}
	return .Participants
}

// GetVersion returns value of Version field.
func ( *ChatParticipants) () ( int) {
	if  == nil {
		return
	}
	return .Version
}

// MapParticipants returns field Participants wrapped in ChatParticipantClassArray helper.
func ( *ChatParticipants) () ( ChatParticipantClassArray) {
	return ChatParticipantClassArray(.Participants)
}

// ChatParticipantsClassName is schema name of ChatParticipantsClass.
const ChatParticipantsClassName = "ChatParticipants"

// ChatParticipantsClass represents ChatParticipants generic type.
//
// See https://core.telegram.org/type/ChatParticipants for reference.
//
// Example:
//
//	g, err := tg.DecodeChatParticipants(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.ChatParticipantsForbidden: // chatParticipantsForbidden#8763d3e1
//	case *tg.ChatParticipants: // chatParticipants#3cbc93f8
//	default: panic(v)
//	}
type ChatParticipantsClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ChatParticipantsClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// Group ID
	GetChatID() (value int64)

	// AsNotForbidden tries to map ChatParticipantsClass to ChatParticipants.
	AsNotForbidden() (*ChatParticipants, bool)
}

// AsNotForbidden tries to map ChatParticipantsForbidden to ChatParticipants.
func ( *ChatParticipantsForbidden) () (*ChatParticipants, bool) {
	return nil, false
}

// AsNotForbidden tries to map ChatParticipants to ChatParticipants.
func ( *ChatParticipants) () (*ChatParticipants, bool) {
	return , true
}

// DecodeChatParticipants implements binary de-serialization for ChatParticipantsClass.
func ( *bin.Buffer) (ChatParticipantsClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case ChatParticipantsForbiddenTypeID:
		// Decoding chatParticipantsForbidden#8763d3e1.
		 := ChatParticipantsForbidden{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChatParticipantsClass: %w", )
		}
		return &, nil
	case ChatParticipantsTypeID:
		// Decoding chatParticipants#3cbc93f8.
		 := ChatParticipants{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChatParticipantsClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode ChatParticipantsClass: %w", bin.NewUnexpectedID())
	}
}

// ChatParticipants boxes the ChatParticipantsClass providing a helper.
type ChatParticipantsBox struct {
	ChatParticipants ChatParticipantsClass
}

// Decode implements bin.Decoder for ChatParticipantsBox.
func ( *ChatParticipantsBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode ChatParticipantsBox to nil")
	}
	,  := DecodeChatParticipants()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.ChatParticipants = 
	return nil
}

// Encode implements bin.Encode for ChatParticipantsBox.
func ( *ChatParticipantsBox) ( *bin.Buffer) error {
	if  == nil || .ChatParticipants == nil {
		return fmt.Errorf("unable to encode ChatParticipantsClass as nil")
	}
	return .ChatParticipants.Encode()
}