// Code generated by gotdgen, DO NOT EDIT.

package tdapi

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

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

// UserPrivacySettingRuleAllowAll represents TL type `userPrivacySettingRuleAllowAll#8abf1c3f`.
type UserPrivacySettingRuleAllowAll struct {
}

// UserPrivacySettingRuleAllowAllTypeID is TL type id of UserPrivacySettingRuleAllowAll.
const UserPrivacySettingRuleAllowAllTypeID = 0x8abf1c3f

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleAllowAll) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleAllowAll{}
)

func (u *UserPrivacySettingRuleAllowAll) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleAllowAll) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleAllowAll",
		ID:   UserPrivacySettingRuleAllowAllTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleAllowAll) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowAll#8abf1c3f as nil")
	}
	b.PutID(UserPrivacySettingRuleAllowAllTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleAllowAll) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowAll#8abf1c3f as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleAllowAll) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowAll#8abf1c3f to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleAllowAllTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleAllowAll#8abf1c3f: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleAllowAll) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowAll#8abf1c3f to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleAllowAll) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowAll#8abf1c3f as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleAllowAll")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleAllowAll) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowAll#8abf1c3f to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleAllowAll"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowAll#8abf1c3f: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserPrivacySettingRuleAllowContacts represents TL type `userPrivacySettingRuleAllowContacts#8f2f2d10`.
type UserPrivacySettingRuleAllowContacts struct {
}

// UserPrivacySettingRuleAllowContactsTypeID is TL type id of UserPrivacySettingRuleAllowContacts.
const UserPrivacySettingRuleAllowContactsTypeID = 0x8f2f2d10

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleAllowContacts) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleAllowContacts{}
)

func (u *UserPrivacySettingRuleAllowContacts) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleAllowContacts) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleAllowContacts",
		ID:   UserPrivacySettingRuleAllowContactsTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleAllowContacts) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowContacts#8f2f2d10 as nil")
	}
	b.PutID(UserPrivacySettingRuleAllowContactsTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleAllowContacts) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowContacts#8f2f2d10 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleAllowContacts) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowContacts#8f2f2d10 to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleAllowContactsTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleAllowContacts#8f2f2d10: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleAllowContacts) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowContacts#8f2f2d10 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleAllowContacts) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowContacts#8f2f2d10 as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleAllowContacts")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleAllowContacts) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowContacts#8f2f2d10 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleAllowContacts"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowContacts#8f2f2d10: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserPrivacySettingRuleAllowBots represents TL type `userPrivacySettingRuleAllowBots#53b2871d`.
type UserPrivacySettingRuleAllowBots struct {
}

// UserPrivacySettingRuleAllowBotsTypeID is TL type id of UserPrivacySettingRuleAllowBots.
const UserPrivacySettingRuleAllowBotsTypeID = 0x53b2871d

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleAllowBots) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleAllowBots{}
)

func (u *UserPrivacySettingRuleAllowBots) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleAllowBots) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleAllowBots",
		ID:   UserPrivacySettingRuleAllowBotsTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleAllowBots) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowBots#53b2871d as nil")
	}
	b.PutID(UserPrivacySettingRuleAllowBotsTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleAllowBots) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowBots#53b2871d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleAllowBots) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowBots#53b2871d to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleAllowBotsTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleAllowBots#53b2871d: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleAllowBots) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowBots#53b2871d to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleAllowBots) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowBots#53b2871d as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleAllowBots")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleAllowBots) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowBots#53b2871d to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleAllowBots"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowBots#53b2871d: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserPrivacySettingRuleAllowPremiumUsers represents TL type `userPrivacySettingRuleAllowPremiumUsers#60ce8541`.
type UserPrivacySettingRuleAllowPremiumUsers struct {
}

// UserPrivacySettingRuleAllowPremiumUsersTypeID is TL type id of UserPrivacySettingRuleAllowPremiumUsers.
const UserPrivacySettingRuleAllowPremiumUsersTypeID = 0x60ce8541

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleAllowPremiumUsers) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleAllowPremiumUsers{}
)

func (u *UserPrivacySettingRuleAllowPremiumUsers) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleAllowPremiumUsers) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleAllowPremiumUsers",
		ID:   UserPrivacySettingRuleAllowPremiumUsersTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleAllowPremiumUsers) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowPremiumUsers#60ce8541 as nil")
	}
	b.PutID(UserPrivacySettingRuleAllowPremiumUsersTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleAllowPremiumUsers) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowPremiumUsers#60ce8541 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleAllowPremiumUsers) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowPremiumUsers#60ce8541 to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleAllowPremiumUsersTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleAllowPremiumUsers#60ce8541: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleAllowPremiumUsers) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowPremiumUsers#60ce8541 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleAllowPremiumUsers) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowPremiumUsers#60ce8541 as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleAllowPremiumUsers")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleAllowPremiumUsers) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowPremiumUsers#60ce8541 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleAllowPremiumUsers"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowPremiumUsers#60ce8541: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserPrivacySettingRuleAllowUsers represents TL type `userPrivacySettingRuleAllowUsers#d1570b70`.
type UserPrivacySettingRuleAllowUsers struct {
	// The user identifiers, total number of users in all rules must not exceed 1000
	UserIDs []int64
}

// UserPrivacySettingRuleAllowUsersTypeID is TL type id of UserPrivacySettingRuleAllowUsers.
const UserPrivacySettingRuleAllowUsersTypeID = 0xd1570b70

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleAllowUsers) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleAllowUsers{}
)

func (u *UserPrivacySettingRuleAllowUsers) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.UserIDs == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleAllowUsers) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleAllowUsers",
		ID:   UserPrivacySettingRuleAllowUsersTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserIDs",
			SchemaName: "user_ids",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleAllowUsers) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowUsers#d1570b70 as nil")
	}
	b.PutID(UserPrivacySettingRuleAllowUsersTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleAllowUsers) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowUsers#d1570b70 as nil")
	}
	b.PutInt(len(u.UserIDs))
	for _, v := range u.UserIDs {
		b.PutInt53(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleAllowUsers) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowUsers#d1570b70 to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleAllowUsersTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleAllowUsers#d1570b70: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleAllowUsers) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowUsers#d1570b70 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode userPrivacySettingRuleAllowUsers#d1570b70: field user_ids: %w", err)
		}

		if headerLen > 0 {
			u.UserIDs = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowUsers#d1570b70: field user_ids: %w", err)
			}
			u.UserIDs = append(u.UserIDs, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleAllowUsers) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowUsers#d1570b70 as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleAllowUsers")
	b.Comma()
	b.FieldStart("user_ids")
	b.ArrStart()
	for _, v := range u.UserIDs {
		b.PutInt53(v)
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleAllowUsers) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowUsers#d1570b70 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleAllowUsers"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowUsers#d1570b70: %w", err)
			}
		case "user_ids":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := b.Int53()
				if err != nil {
					return fmt.Errorf("unable to decode userPrivacySettingRuleAllowUsers#d1570b70: field user_ids: %w", err)
				}
				u.UserIDs = append(u.UserIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowUsers#d1570b70: field user_ids: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetUserIDs returns value of UserIDs field.
func (u *UserPrivacySettingRuleAllowUsers) GetUserIDs() (value []int64) {
	if u == nil {
		return
	}
	return u.UserIDs
}

// UserPrivacySettingRuleAllowChatMembers represents TL type `userPrivacySettingRuleAllowChatMembers#f249b617`.
type UserPrivacySettingRuleAllowChatMembers struct {
	// The chat identifiers, total number of chats in all rules must not exceed 20
	ChatIDs []int64
}

// UserPrivacySettingRuleAllowChatMembersTypeID is TL type id of UserPrivacySettingRuleAllowChatMembers.
const UserPrivacySettingRuleAllowChatMembersTypeID = 0xf249b617

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleAllowChatMembers) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleAllowChatMembers{}
)

func (u *UserPrivacySettingRuleAllowChatMembers) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.ChatIDs == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleAllowChatMembers) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleAllowChatMembers",
		ID:   UserPrivacySettingRuleAllowChatMembersTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatIDs",
			SchemaName: "chat_ids",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleAllowChatMembers) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowChatMembers#f249b617 as nil")
	}
	b.PutID(UserPrivacySettingRuleAllowChatMembersTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleAllowChatMembers) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowChatMembers#f249b617 as nil")
	}
	b.PutInt(len(u.ChatIDs))
	for _, v := range u.ChatIDs {
		b.PutInt53(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleAllowChatMembers) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowChatMembers#f249b617 to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleAllowChatMembersTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleAllowChatMembers#f249b617: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleAllowChatMembers) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowChatMembers#f249b617 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode userPrivacySettingRuleAllowChatMembers#f249b617: field chat_ids: %w", err)
		}

		if headerLen > 0 {
			u.ChatIDs = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowChatMembers#f249b617: field chat_ids: %w", err)
			}
			u.ChatIDs = append(u.ChatIDs, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleAllowChatMembers) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleAllowChatMembers#f249b617 as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleAllowChatMembers")
	b.Comma()
	b.FieldStart("chat_ids")
	b.ArrStart()
	for _, v := range u.ChatIDs {
		b.PutInt53(v)
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleAllowChatMembers) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleAllowChatMembers#f249b617 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleAllowChatMembers"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowChatMembers#f249b617: %w", err)
			}
		case "chat_ids":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := b.Int53()
				if err != nil {
					return fmt.Errorf("unable to decode userPrivacySettingRuleAllowChatMembers#f249b617: field chat_ids: %w", err)
				}
				u.ChatIDs = append(u.ChatIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleAllowChatMembers#f249b617: field chat_ids: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatIDs returns value of ChatIDs field.
func (u *UserPrivacySettingRuleAllowChatMembers) GetChatIDs() (value []int64) {
	if u == nil {
		return
	}
	return u.ChatIDs
}

// UserPrivacySettingRuleRestrictAll represents TL type `userPrivacySettingRuleRestrictAll#ac2a9550`.
type UserPrivacySettingRuleRestrictAll struct {
}

// UserPrivacySettingRuleRestrictAllTypeID is TL type id of UserPrivacySettingRuleRestrictAll.
const UserPrivacySettingRuleRestrictAllTypeID = 0xac2a9550

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleRestrictAll) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleRestrictAll{}
)

func (u *UserPrivacySettingRuleRestrictAll) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleRestrictAll) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleRestrictAll",
		ID:   UserPrivacySettingRuleRestrictAllTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleRestrictAll) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictAll#ac2a9550 as nil")
	}
	b.PutID(UserPrivacySettingRuleRestrictAllTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleRestrictAll) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictAll#ac2a9550 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleRestrictAll) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictAll#ac2a9550 to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleRestrictAllTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictAll#ac2a9550: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleRestrictAll) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictAll#ac2a9550 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleRestrictAll) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictAll#ac2a9550 as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleRestrictAll")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleRestrictAll) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictAll#ac2a9550 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleRestrictAll"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictAll#ac2a9550: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserPrivacySettingRuleRestrictContacts represents TL type `userPrivacySettingRuleRestrictContacts#3c1acd02`.
type UserPrivacySettingRuleRestrictContacts struct {
}

// UserPrivacySettingRuleRestrictContactsTypeID is TL type id of UserPrivacySettingRuleRestrictContacts.
const UserPrivacySettingRuleRestrictContactsTypeID = 0x3c1acd02

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleRestrictContacts) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleRestrictContacts{}
)

func (u *UserPrivacySettingRuleRestrictContacts) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleRestrictContacts) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleRestrictContacts",
		ID:   UserPrivacySettingRuleRestrictContactsTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleRestrictContacts) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictContacts#3c1acd02 as nil")
	}
	b.PutID(UserPrivacySettingRuleRestrictContactsTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleRestrictContacts) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictContacts#3c1acd02 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleRestrictContacts) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictContacts#3c1acd02 to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleRestrictContactsTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictContacts#3c1acd02: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleRestrictContacts) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictContacts#3c1acd02 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleRestrictContacts) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictContacts#3c1acd02 as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleRestrictContacts")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleRestrictContacts) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictContacts#3c1acd02 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleRestrictContacts"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictContacts#3c1acd02: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserPrivacySettingRuleRestrictBots represents TL type `userPrivacySettingRuleRestrictBots#8e996e5d`.
type UserPrivacySettingRuleRestrictBots struct {
}

// UserPrivacySettingRuleRestrictBotsTypeID is TL type id of UserPrivacySettingRuleRestrictBots.
const UserPrivacySettingRuleRestrictBotsTypeID = 0x8e996e5d

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleRestrictBots) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleRestrictBots{}
)

func (u *UserPrivacySettingRuleRestrictBots) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleRestrictBots) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleRestrictBots",
		ID:   UserPrivacySettingRuleRestrictBotsTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleRestrictBots) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictBots#8e996e5d as nil")
	}
	b.PutID(UserPrivacySettingRuleRestrictBotsTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleRestrictBots) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictBots#8e996e5d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleRestrictBots) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictBots#8e996e5d to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleRestrictBotsTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictBots#8e996e5d: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleRestrictBots) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictBots#8e996e5d to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleRestrictBots) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictBots#8e996e5d as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleRestrictBots")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleRestrictBots) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictBots#8e996e5d to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleRestrictBots"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictBots#8e996e5d: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserPrivacySettingRuleRestrictUsers represents TL type `userPrivacySettingRuleRestrictUsers#4d392a91`.
type UserPrivacySettingRuleRestrictUsers struct {
	// The user identifiers, total number of users in all rules must not exceed 1000
	UserIDs []int64
}

// UserPrivacySettingRuleRestrictUsersTypeID is TL type id of UserPrivacySettingRuleRestrictUsers.
const UserPrivacySettingRuleRestrictUsersTypeID = 0x4d392a91

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleRestrictUsers) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleRestrictUsers{}
)

func (u *UserPrivacySettingRuleRestrictUsers) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.UserIDs == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleRestrictUsers) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleRestrictUsers",
		ID:   UserPrivacySettingRuleRestrictUsersTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserIDs",
			SchemaName: "user_ids",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleRestrictUsers) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictUsers#4d392a91 as nil")
	}
	b.PutID(UserPrivacySettingRuleRestrictUsersTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleRestrictUsers) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictUsers#4d392a91 as nil")
	}
	b.PutInt(len(u.UserIDs))
	for _, v := range u.UserIDs {
		b.PutInt53(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleRestrictUsers) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictUsers#4d392a91 to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleRestrictUsersTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictUsers#4d392a91: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleRestrictUsers) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictUsers#4d392a91 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictUsers#4d392a91: field user_ids: %w", err)
		}

		if headerLen > 0 {
			u.UserIDs = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictUsers#4d392a91: field user_ids: %w", err)
			}
			u.UserIDs = append(u.UserIDs, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleRestrictUsers) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictUsers#4d392a91 as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleRestrictUsers")
	b.Comma()
	b.FieldStart("user_ids")
	b.ArrStart()
	for _, v := range u.UserIDs {
		b.PutInt53(v)
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleRestrictUsers) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictUsers#4d392a91 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleRestrictUsers"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictUsers#4d392a91: %w", err)
			}
		case "user_ids":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := b.Int53()
				if err != nil {
					return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictUsers#4d392a91: field user_ids: %w", err)
				}
				u.UserIDs = append(u.UserIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictUsers#4d392a91: field user_ids: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetUserIDs returns value of UserIDs field.
func (u *UserPrivacySettingRuleRestrictUsers) GetUserIDs() (value []int64) {
	if u == nil {
		return
	}
	return u.UserIDs
}

// UserPrivacySettingRuleRestrictChatMembers represents TL type `userPrivacySettingRuleRestrictChatMembers#fc00b920`.
type UserPrivacySettingRuleRestrictChatMembers struct {
	// The chat identifiers, total number of chats in all rules must not exceed 20
	ChatIDs []int64
}

// UserPrivacySettingRuleRestrictChatMembersTypeID is TL type id of UserPrivacySettingRuleRestrictChatMembers.
const UserPrivacySettingRuleRestrictChatMembersTypeID = 0xfc00b920

// construct implements constructor of UserPrivacySettingRuleClass.
func (u UserPrivacySettingRuleRestrictChatMembers) construct() UserPrivacySettingRuleClass { return &u }

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

	_ UserPrivacySettingRuleClass = &UserPrivacySettingRuleRestrictChatMembers{}
)

func (u *UserPrivacySettingRuleRestrictChatMembers) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.ChatIDs == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserPrivacySettingRuleRestrictChatMembers) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userPrivacySettingRuleRestrictChatMembers",
		ID:   UserPrivacySettingRuleRestrictChatMembersTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatIDs",
			SchemaName: "chat_ids",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserPrivacySettingRuleRestrictChatMembers) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictChatMembers#fc00b920 as nil")
	}
	b.PutID(UserPrivacySettingRuleRestrictChatMembersTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserPrivacySettingRuleRestrictChatMembers) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictChatMembers#fc00b920 as nil")
	}
	b.PutInt(len(u.ChatIDs))
	for _, v := range u.ChatIDs {
		b.PutInt53(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserPrivacySettingRuleRestrictChatMembers) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictChatMembers#fc00b920 to nil")
	}
	if err := b.ConsumeID(UserPrivacySettingRuleRestrictChatMembersTypeID); err != nil {
		return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictChatMembers#fc00b920: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserPrivacySettingRuleRestrictChatMembers) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictChatMembers#fc00b920 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictChatMembers#fc00b920: field chat_ids: %w", err)
		}

		if headerLen > 0 {
			u.ChatIDs = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictChatMembers#fc00b920: field chat_ids: %w", err)
			}
			u.ChatIDs = append(u.ChatIDs, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserPrivacySettingRuleRestrictChatMembers) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userPrivacySettingRuleRestrictChatMembers#fc00b920 as nil")
	}
	b.ObjStart()
	b.PutID("userPrivacySettingRuleRestrictChatMembers")
	b.Comma()
	b.FieldStart("chat_ids")
	b.ArrStart()
	for _, v := range u.ChatIDs {
		b.PutInt53(v)
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserPrivacySettingRuleRestrictChatMembers) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userPrivacySettingRuleRestrictChatMembers#fc00b920 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userPrivacySettingRuleRestrictChatMembers"); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictChatMembers#fc00b920: %w", err)
			}
		case "chat_ids":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := b.Int53()
				if err != nil {
					return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictChatMembers#fc00b920: field chat_ids: %w", err)
				}
				u.ChatIDs = append(u.ChatIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode userPrivacySettingRuleRestrictChatMembers#fc00b920: field chat_ids: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatIDs returns value of ChatIDs field.
func (u *UserPrivacySettingRuleRestrictChatMembers) GetChatIDs() (value []int64) {
	if u == nil {
		return
	}
	return u.ChatIDs
}

// UserPrivacySettingRuleClassName is schema name of UserPrivacySettingRuleClass.
const UserPrivacySettingRuleClassName = "UserPrivacySettingRule"

// UserPrivacySettingRuleClass represents UserPrivacySettingRule generic type.
//
// Example:
//
//	g, err := tdapi.DecodeUserPrivacySettingRule(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.UserPrivacySettingRuleAllowAll: // userPrivacySettingRuleAllowAll#8abf1c3f
//	case *tdapi.UserPrivacySettingRuleAllowContacts: // userPrivacySettingRuleAllowContacts#8f2f2d10
//	case *tdapi.UserPrivacySettingRuleAllowBots: // userPrivacySettingRuleAllowBots#53b2871d
//	case *tdapi.UserPrivacySettingRuleAllowPremiumUsers: // userPrivacySettingRuleAllowPremiumUsers#60ce8541
//	case *tdapi.UserPrivacySettingRuleAllowUsers: // userPrivacySettingRuleAllowUsers#d1570b70
//	case *tdapi.UserPrivacySettingRuleAllowChatMembers: // userPrivacySettingRuleAllowChatMembers#f249b617
//	case *tdapi.UserPrivacySettingRuleRestrictAll: // userPrivacySettingRuleRestrictAll#ac2a9550
//	case *tdapi.UserPrivacySettingRuleRestrictContacts: // userPrivacySettingRuleRestrictContacts#3c1acd02
//	case *tdapi.UserPrivacySettingRuleRestrictBots: // userPrivacySettingRuleRestrictBots#8e996e5d
//	case *tdapi.UserPrivacySettingRuleRestrictUsers: // userPrivacySettingRuleRestrictUsers#4d392a91
//	case *tdapi.UserPrivacySettingRuleRestrictChatMembers: // userPrivacySettingRuleRestrictChatMembers#fc00b920
//	default: panic(v)
//	}
type UserPrivacySettingRuleClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() UserPrivacySettingRuleClass

	// 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

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeUserPrivacySettingRule implements binary de-serialization for UserPrivacySettingRuleClass.
func DecodeUserPrivacySettingRule(buf *bin.Buffer) (UserPrivacySettingRuleClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case UserPrivacySettingRuleAllowAllTypeID:
		// Decoding userPrivacySettingRuleAllowAll#8abf1c3f.
		v := UserPrivacySettingRuleAllowAll{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleAllowContactsTypeID:
		// Decoding userPrivacySettingRuleAllowContacts#8f2f2d10.
		v := UserPrivacySettingRuleAllowContacts{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleAllowBotsTypeID:
		// Decoding userPrivacySettingRuleAllowBots#53b2871d.
		v := UserPrivacySettingRuleAllowBots{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleAllowPremiumUsersTypeID:
		// Decoding userPrivacySettingRuleAllowPremiumUsers#60ce8541.
		v := UserPrivacySettingRuleAllowPremiumUsers{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleAllowUsersTypeID:
		// Decoding userPrivacySettingRuleAllowUsers#d1570b70.
		v := UserPrivacySettingRuleAllowUsers{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleAllowChatMembersTypeID:
		// Decoding userPrivacySettingRuleAllowChatMembers#f249b617.
		v := UserPrivacySettingRuleAllowChatMembers{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleRestrictAllTypeID:
		// Decoding userPrivacySettingRuleRestrictAll#ac2a9550.
		v := UserPrivacySettingRuleRestrictAll{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleRestrictContactsTypeID:
		// Decoding userPrivacySettingRuleRestrictContacts#3c1acd02.
		v := UserPrivacySettingRuleRestrictContacts{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleRestrictBotsTypeID:
		// Decoding userPrivacySettingRuleRestrictBots#8e996e5d.
		v := UserPrivacySettingRuleRestrictBots{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleRestrictUsersTypeID:
		// Decoding userPrivacySettingRuleRestrictUsers#4d392a91.
		v := UserPrivacySettingRuleRestrictUsers{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case UserPrivacySettingRuleRestrictChatMembersTypeID:
		// Decoding userPrivacySettingRuleRestrictChatMembers#fc00b920.
		v := UserPrivacySettingRuleRestrictChatMembers{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONUserPrivacySettingRule implements binary de-serialization for UserPrivacySettingRuleClass.
func DecodeTDLibJSONUserPrivacySettingRule(buf tdjson.Decoder) (UserPrivacySettingRuleClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "userPrivacySettingRuleAllowAll":
		// Decoding userPrivacySettingRuleAllowAll#8abf1c3f.
		v := UserPrivacySettingRuleAllowAll{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleAllowContacts":
		// Decoding userPrivacySettingRuleAllowContacts#8f2f2d10.
		v := UserPrivacySettingRuleAllowContacts{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleAllowBots":
		// Decoding userPrivacySettingRuleAllowBots#53b2871d.
		v := UserPrivacySettingRuleAllowBots{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleAllowPremiumUsers":
		// Decoding userPrivacySettingRuleAllowPremiumUsers#60ce8541.
		v := UserPrivacySettingRuleAllowPremiumUsers{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleAllowUsers":
		// Decoding userPrivacySettingRuleAllowUsers#d1570b70.
		v := UserPrivacySettingRuleAllowUsers{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleAllowChatMembers":
		// Decoding userPrivacySettingRuleAllowChatMembers#f249b617.
		v := UserPrivacySettingRuleAllowChatMembers{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleRestrictAll":
		// Decoding userPrivacySettingRuleRestrictAll#ac2a9550.
		v := UserPrivacySettingRuleRestrictAll{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleRestrictContacts":
		// Decoding userPrivacySettingRuleRestrictContacts#3c1acd02.
		v := UserPrivacySettingRuleRestrictContacts{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleRestrictBots":
		// Decoding userPrivacySettingRuleRestrictBots#8e996e5d.
		v := UserPrivacySettingRuleRestrictBots{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleRestrictUsers":
		// Decoding userPrivacySettingRuleRestrictUsers#4d392a91.
		v := UserPrivacySettingRuleRestrictUsers{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	case "userPrivacySettingRuleRestrictChatMembers":
		// Decoding userPrivacySettingRuleRestrictChatMembers#fc00b920.
		v := UserPrivacySettingRuleRestrictChatMembers{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode UserPrivacySettingRuleClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// UserPrivacySettingRule boxes the UserPrivacySettingRuleClass providing a helper.
type UserPrivacySettingRuleBox struct {
	UserPrivacySettingRule UserPrivacySettingRuleClass
}

// Decode implements bin.Decoder for UserPrivacySettingRuleBox.
func (b *UserPrivacySettingRuleBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode UserPrivacySettingRuleBox to nil")
	}
	v, err := DecodeUserPrivacySettingRule(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.UserPrivacySettingRule = v
	return nil
}

// Encode implements bin.Encode for UserPrivacySettingRuleBox.
func (b *UserPrivacySettingRuleBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.UserPrivacySettingRule == nil {
		return fmt.Errorf("unable to encode UserPrivacySettingRuleClass as nil")
	}
	return b.UserPrivacySettingRule.Encode(buf)
}

// DecodeTDLibJSON implements bin.Decoder for UserPrivacySettingRuleBox.
func (b *UserPrivacySettingRuleBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode UserPrivacySettingRuleBox to nil")
	}
	v, err := DecodeTDLibJSONUserPrivacySettingRule(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.UserPrivacySettingRule = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for UserPrivacySettingRuleBox.
func (b *UserPrivacySettingRuleBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.UserPrivacySettingRule == nil {
		return fmt.Errorf("unable to encode UserPrivacySettingRuleClass as nil")
	}
	return b.UserPrivacySettingRule.EncodeTDLibJSON(buf)
}
