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

// AccountPrivacyRules represents TL type `account.privacyRules#50a04e45`.
// Privacy rules
//
// See https://core.telegram.org/constructor/account.privacyRules for reference.
type AccountPrivacyRules struct {
	// Privacy rules
	Rules []PrivacyRuleClass
	// Chats to which the rules apply
	Chats []ChatClass
	// Users to which the rules apply
	Users []UserClass
}

// AccountPrivacyRulesTypeID is TL type id of AccountPrivacyRules.
const AccountPrivacyRulesTypeID = 0x50a04e45

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

func ( *AccountPrivacyRules) () bool {
	if  == nil {
		return true
	}
	if !(.Rules == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AccountPrivacyRules from given interface.
func ( *AccountPrivacyRules) ( interface {
	() ( []PrivacyRuleClass)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Rules = .()
	.Chats = .()
	.Users = .()
}

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

// TypeName returns name of type in TL schema.
func (*AccountPrivacyRules) () string {
	return "account.privacyRules"
}

// TypeInfo returns info about TL type.
func ( *AccountPrivacyRules) () tdp.Type {
	 := tdp.Type{
		Name: "account.privacyRules",
		ID:   AccountPrivacyRulesTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Rules",
			SchemaName: "rules",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *AccountPrivacyRules) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.privacyRules#50a04e45 as nil")
	}
	.PutID(AccountPrivacyRulesTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccountPrivacyRules) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.privacyRules#50a04e45 as nil")
	}
	.PutVectorHeader(len(.Rules))
	for ,  := range .Rules {
		if  == nil {
			return fmt.Errorf("unable to encode account.privacyRules#50a04e45: field rules element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode account.privacyRules#50a04e45: field rules element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode account.privacyRules#50a04e45: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode account.privacyRules#50a04e45: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode account.privacyRules#50a04e45: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode account.privacyRules#50a04e45: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *AccountPrivacyRules) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.privacyRules#50a04e45 to nil")
	}
	if  := .ConsumeID(AccountPrivacyRulesTypeID);  != nil {
		return fmt.Errorf("unable to decode account.privacyRules#50a04e45: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *AccountPrivacyRules) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.privacyRules#50a04e45 to nil")
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode account.privacyRules#50a04e45: field rules: %w", )
		}

		if  > 0 {
			.Rules = make([]PrivacyRuleClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePrivacyRule()
			if  != nil {
				return fmt.Errorf("unable to decode account.privacyRules#50a04e45: field rules: %w", )
			}
			.Rules = append(.Rules, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode account.privacyRules#50a04e45: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode account.privacyRules#50a04e45: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode account.privacyRules#50a04e45: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode account.privacyRules#50a04e45: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	return nil
}

// GetRules returns value of Rules field.
func ( *AccountPrivacyRules) () ( []PrivacyRuleClass) {
	if  == nil {
		return
	}
	return .Rules
}

// GetChats returns value of Chats field.
func ( *AccountPrivacyRules) () ( []ChatClass) {
	if  == nil {
		return
	}
	return .Chats
}

// GetUsers returns value of Users field.
func ( *AccountPrivacyRules) () ( []UserClass) {
	if  == nil {
		return
	}
	return .Users
}

// MapRules returns field Rules wrapped in PrivacyRuleClassArray helper.
func ( *AccountPrivacyRules) () ( PrivacyRuleClassArray) {
	return PrivacyRuleClassArray(.Rules)
}

// MapChats returns field Chats wrapped in ChatClassArray helper.
func ( *AccountPrivacyRules) () ( ChatClassArray) {
	return ChatClassArray(.Chats)
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func ( *AccountPrivacyRules) () ( UserClassArray) {
	return UserClassArray(.Users)
}