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

// BusinessRecipients represents TL type `businessRecipients#21108ff7`.
// Specifies the chats that can receive Telegram Business away »¹ and greeting »²
// messages.
// If exclude_selected is set, specifies all chats that cannot receive Telegram Business
// away »¹ and greeting »² messages.
//
// Links:
//  1. https://core.telegram.org/api/business#away-messages
//  2. https://core.telegram.org/api/business#greeting-messages
//  3. https://core.telegram.org/api/business#away-messages
//  4. https://core.telegram.org/api/business#greeting-messages
//
// See https://core.telegram.org/constructor/businessRecipients for reference.
type BusinessRecipients struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// All existing private chats.
	ExistingChats bool
	// All new private chats.
	NewChats bool
	// All private chats with contacts.
	Contacts bool
	// All private chats with non-contacts.
	NonContacts bool
	// If set, inverts the selection.
	ExcludeSelected bool
	// Only private chats with the specified users.
	//
	// Use SetUsers and GetUsers helpers.
	Users []int64
}

// BusinessRecipientsTypeID is TL type id of BusinessRecipients.
const BusinessRecipientsTypeID = 0x21108ff7

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

func ( *BusinessRecipients) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.ExistingChats == false) {
		return false
	}
	if !(.NewChats == false) {
		return false
	}
	if !(.Contacts == false) {
		return false
	}
	if !(.NonContacts == false) {
		return false
	}
	if !(.ExcludeSelected == false) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills BusinessRecipients from given interface.
func ( *BusinessRecipients) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( []int64,  bool)
}) {
	.ExistingChats = .()
	.NewChats = .()
	.Contacts = .()
	.NonContacts = .()
	.ExcludeSelected = .()
	if ,  := .();  {
		.Users = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *BusinessRecipients) () tdp.Type {
	 := tdp.Type{
		Name: "businessRecipients",
		ID:   BusinessRecipientsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ExistingChats",
			SchemaName: "existing_chats",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "NewChats",
			SchemaName: "new_chats",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Contacts",
			SchemaName: "contacts",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "NonContacts",
			SchemaName: "non_contacts",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "ExcludeSelected",
			SchemaName: "exclude_selected",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Users",
			SchemaName: "users",
			Null:       !.Flags.Has(4),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *BusinessRecipients) () {
	if !(.ExistingChats == false) {
		.Flags.Set(0)
	}
	if !(.NewChats == false) {
		.Flags.Set(1)
	}
	if !(.Contacts == false) {
		.Flags.Set(2)
	}
	if !(.NonContacts == false) {
		.Flags.Set(3)
	}
	if !(.ExcludeSelected == false) {
		.Flags.Set(5)
	}
	if !(.Users == nil) {
		.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func ( *BusinessRecipients) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode businessRecipients#21108ff7 as nil")
	}
	.PutID(BusinessRecipientsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *BusinessRecipients) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode businessRecipients#21108ff7 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode businessRecipients#21108ff7: field flags: %w", )
	}
	if .Flags.Has(4) {
		.PutVectorHeader(len(.Users))
		for ,  := range .Users {
			.PutLong()
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *BusinessRecipients) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode businessRecipients#21108ff7 to nil")
	}
	if  := .ConsumeID(BusinessRecipientsTypeID);  != nil {
		return fmt.Errorf("unable to decode businessRecipients#21108ff7: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *BusinessRecipients) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode businessRecipients#21108ff7 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode businessRecipients#21108ff7: field flags: %w", )
		}
	}
	.ExistingChats = .Flags.Has(0)
	.NewChats = .Flags.Has(1)
	.Contacts = .Flags.Has(2)
	.NonContacts = .Flags.Has(3)
	.ExcludeSelected = .Flags.Has(5)
	if .Flags.Has(4) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode businessRecipients#21108ff7: field users: %w", )
		}

		if  > 0 {
			.Users = make([]int64, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .Long()
			if  != nil {
				return fmt.Errorf("unable to decode businessRecipients#21108ff7: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	return nil
}

// SetExistingChats sets value of ExistingChats conditional field.
func ( *BusinessRecipients) ( bool) {
	if  {
		.Flags.Set(0)
		.ExistingChats = true
	} else {
		.Flags.Unset(0)
		.ExistingChats = false
	}
}

// GetExistingChats returns value of ExistingChats conditional field.
func ( *BusinessRecipients) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetNewChats sets value of NewChats conditional field.
func ( *BusinessRecipients) ( bool) {
	if  {
		.Flags.Set(1)
		.NewChats = true
	} else {
		.Flags.Unset(1)
		.NewChats = false
	}
}

// GetNewChats returns value of NewChats conditional field.
func ( *BusinessRecipients) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetContacts sets value of Contacts conditional field.
func ( *BusinessRecipients) ( bool) {
	if  {
		.Flags.Set(2)
		.Contacts = true
	} else {
		.Flags.Unset(2)
		.Contacts = false
	}
}

// GetContacts returns value of Contacts conditional field.
func ( *BusinessRecipients) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetNonContacts sets value of NonContacts conditional field.
func ( *BusinessRecipients) ( bool) {
	if  {
		.Flags.Set(3)
		.NonContacts = true
	} else {
		.Flags.Unset(3)
		.NonContacts = false
	}
}

// GetNonContacts returns value of NonContacts conditional field.
func ( *BusinessRecipients) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetExcludeSelected sets value of ExcludeSelected conditional field.
func ( *BusinessRecipients) ( bool) {
	if  {
		.Flags.Set(5)
		.ExcludeSelected = true
	} else {
		.Flags.Unset(5)
		.ExcludeSelected = false
	}
}

// GetExcludeSelected returns value of ExcludeSelected conditional field.
func ( *BusinessRecipients) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// SetUsers sets value of Users conditional field.
func ( *BusinessRecipients) ( []int64) {
	.Flags.Set(4)
	.Users = 
}

// GetUsers returns value of Users conditional field and
// boolean which is true if field was set.
func ( *BusinessRecipients) () ( []int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .Users, true
}