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

// PassportElementErrorSourceUnspecified represents TL type `passportElementErrorSourceUnspecified#e9734842`.
type PassportElementErrorSourceUnspecified struct {
}

// PassportElementErrorSourceUnspecifiedTypeID is TL type id of PassportElementErrorSourceUnspecified.
const PassportElementErrorSourceUnspecifiedTypeID = 0xe9734842

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceUnspecified) construct() PassportElementErrorSourceClass { return &p }

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceUnspecified{}
)

func (p *PassportElementErrorSourceUnspecified) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceUnspecified) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceUnspecified#e9734842 as nil")
	}
	b.PutID(PassportElementErrorSourceUnspecifiedTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceUnspecified) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceUnspecified#e9734842 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceUnspecified) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceUnspecified#e9734842 to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceUnspecifiedTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceUnspecified#e9734842: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceUnspecified) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceUnspecified#e9734842 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceUnspecified) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceUnspecified#e9734842 to nil")
	}

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

// PassportElementErrorSourceDataField represents TL type `passportElementErrorSourceDataField#ed9a5ce8`.
type PassportElementErrorSourceDataField struct {
	// Field name
	FieldName string
}

// PassportElementErrorSourceDataFieldTypeID is TL type id of PassportElementErrorSourceDataField.
const PassportElementErrorSourceDataFieldTypeID = 0xed9a5ce8

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceDataField) construct() PassportElementErrorSourceClass { return &p }

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceDataField{}
)

func (p *PassportElementErrorSourceDataField) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.FieldName == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementErrorSourceDataField) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementErrorSourceDataField",
		ID:   PassportElementErrorSourceDataFieldTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "FieldName",
			SchemaName: "field_name",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceDataField) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceDataField#ed9a5ce8 as nil")
	}
	b.PutID(PassportElementErrorSourceDataFieldTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceDataField) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceDataField#ed9a5ce8 as nil")
	}
	b.PutString(p.FieldName)
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceDataField) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceDataField#ed9a5ce8 to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceDataFieldTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceDataField#ed9a5ce8: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceDataField) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceDataField#ed9a5ce8 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode passportElementErrorSourceDataField#ed9a5ce8: field field_name: %w", err)
		}
		p.FieldName = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementErrorSourceDataField) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceDataField#ed9a5ce8 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementErrorSourceDataField")
	b.Comma()
	b.FieldStart("field_name")
	b.PutString(p.FieldName)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceDataField) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceDataField#ed9a5ce8 to nil")
	}

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

// GetFieldName returns value of FieldName field.
func (p *PassportElementErrorSourceDataField) GetFieldName() (value string) {
	if p == nil {
		return
	}
	return p.FieldName
}

// PassportElementErrorSourceFrontSide represents TL type `passportElementErrorSourceFrontSide#70fd7334`.
type PassportElementErrorSourceFrontSide struct {
}

// PassportElementErrorSourceFrontSideTypeID is TL type id of PassportElementErrorSourceFrontSide.
const PassportElementErrorSourceFrontSideTypeID = 0x70fd7334

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceFrontSide) construct() PassportElementErrorSourceClass { return &p }

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceFrontSide{}
)

func (p *PassportElementErrorSourceFrontSide) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceFrontSide) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFrontSide#70fd7334 as nil")
	}
	b.PutID(PassportElementErrorSourceFrontSideTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceFrontSide) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFrontSide#70fd7334 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceFrontSide) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFrontSide#70fd7334 to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceFrontSideTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceFrontSide#70fd7334: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceFrontSide) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFrontSide#70fd7334 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementErrorSourceFrontSide) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFrontSide#70fd7334 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementErrorSourceFrontSide")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceFrontSide) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFrontSide#70fd7334 to nil")
	}

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

// PassportElementErrorSourceReverseSide represents TL type `passportElementErrorSourceReverseSide#725bf9f7`.
type PassportElementErrorSourceReverseSide struct {
}

// PassportElementErrorSourceReverseSideTypeID is TL type id of PassportElementErrorSourceReverseSide.
const PassportElementErrorSourceReverseSideTypeID = 0x725bf9f7

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceReverseSide) construct() PassportElementErrorSourceClass { return &p }

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceReverseSide{}
)

func (p *PassportElementErrorSourceReverseSide) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceReverseSide) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceReverseSide#725bf9f7 as nil")
	}
	b.PutID(PassportElementErrorSourceReverseSideTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceReverseSide) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceReverseSide#725bf9f7 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceReverseSide) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceReverseSide#725bf9f7 to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceReverseSideTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceReverseSide#725bf9f7: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceReverseSide) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceReverseSide#725bf9f7 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementErrorSourceReverseSide) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceReverseSide#725bf9f7 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementErrorSourceReverseSide")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceReverseSide) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceReverseSide#725bf9f7 to nil")
	}

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

// PassportElementErrorSourceSelfie represents TL type `passportElementErrorSourceSelfie#d07e1428`.
type PassportElementErrorSourceSelfie struct {
}

// PassportElementErrorSourceSelfieTypeID is TL type id of PassportElementErrorSourceSelfie.
const PassportElementErrorSourceSelfieTypeID = 0xd07e1428

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceSelfie) construct() PassportElementErrorSourceClass { return &p }

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceSelfie{}
)

func (p *PassportElementErrorSourceSelfie) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceSelfie) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceSelfie#d07e1428 as nil")
	}
	b.PutID(PassportElementErrorSourceSelfieTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceSelfie) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceSelfie#d07e1428 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceSelfie) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceSelfie#d07e1428 to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceSelfieTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceSelfie#d07e1428: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceSelfie) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceSelfie#d07e1428 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceSelfie) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceSelfie#d07e1428 to nil")
	}

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

// PassportElementErrorSourceTranslationFile represents TL type `passportElementErrorSourceTranslationFile#d6e53714`.
type PassportElementErrorSourceTranslationFile struct {
	// Index of a file with the error
	FileIndex int32
}

// PassportElementErrorSourceTranslationFileTypeID is TL type id of PassportElementErrorSourceTranslationFile.
const PassportElementErrorSourceTranslationFileTypeID = 0xd6e53714

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceTranslationFile) construct() PassportElementErrorSourceClass {
	return &p
}

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceTranslationFile{}
)

func (p *PassportElementErrorSourceTranslationFile) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.FileIndex == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementErrorSourceTranslationFile) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementErrorSourceTranslationFile",
		ID:   PassportElementErrorSourceTranslationFileTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "FileIndex",
			SchemaName: "file_index",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceTranslationFile) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceTranslationFile#d6e53714 as nil")
	}
	b.PutID(PassportElementErrorSourceTranslationFileTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceTranslationFile) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceTranslationFile#d6e53714 as nil")
	}
	b.PutInt32(p.FileIndex)
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceTranslationFile) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceTranslationFile#d6e53714 to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceTranslationFileTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceTranslationFile#d6e53714: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceTranslationFile) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceTranslationFile#d6e53714 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode passportElementErrorSourceTranslationFile#d6e53714: field file_index: %w", err)
		}
		p.FileIndex = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementErrorSourceTranslationFile) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceTranslationFile#d6e53714 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementErrorSourceTranslationFile")
	b.Comma()
	b.FieldStart("file_index")
	b.PutInt32(p.FileIndex)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceTranslationFile) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceTranslationFile#d6e53714 to nil")
	}

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

// GetFileIndex returns value of FileIndex field.
func (p *PassportElementErrorSourceTranslationFile) GetFileIndex() (value int32) {
	if p == nil {
		return
	}
	return p.FileIndex
}

// PassportElementErrorSourceTranslationFiles represents TL type `passportElementErrorSourceTranslationFiles#22a5a41c`.
type PassportElementErrorSourceTranslationFiles struct {
}

// PassportElementErrorSourceTranslationFilesTypeID is TL type id of PassportElementErrorSourceTranslationFiles.
const PassportElementErrorSourceTranslationFilesTypeID = 0x22a5a41c

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceTranslationFiles) construct() PassportElementErrorSourceClass {
	return &p
}

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceTranslationFiles{}
)

func (p *PassportElementErrorSourceTranslationFiles) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceTranslationFiles) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceTranslationFiles#22a5a41c as nil")
	}
	b.PutID(PassportElementErrorSourceTranslationFilesTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceTranslationFiles) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceTranslationFiles#22a5a41c as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceTranslationFiles) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceTranslationFiles#22a5a41c to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceTranslationFilesTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceTranslationFiles#22a5a41c: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceTranslationFiles) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceTranslationFiles#22a5a41c to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementErrorSourceTranslationFiles) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceTranslationFiles#22a5a41c as nil")
	}
	b.ObjStart()
	b.PutID("passportElementErrorSourceTranslationFiles")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceTranslationFiles) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceTranslationFiles#22a5a41c to nil")
	}

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

// PassportElementErrorSourceFile represents TL type `passportElementErrorSourceFile#786c3b30`.
type PassportElementErrorSourceFile struct {
	// Index of a file with the error
	FileIndex int32
}

// PassportElementErrorSourceFileTypeID is TL type id of PassportElementErrorSourceFile.
const PassportElementErrorSourceFileTypeID = 0x786c3b30

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceFile) construct() PassportElementErrorSourceClass { return &p }

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceFile{}
)

func (p *PassportElementErrorSourceFile) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.FileIndex == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementErrorSourceFile) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementErrorSourceFile",
		ID:   PassportElementErrorSourceFileTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "FileIndex",
			SchemaName: "file_index",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceFile) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFile#786c3b30 as nil")
	}
	b.PutID(PassportElementErrorSourceFileTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceFile) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFile#786c3b30 as nil")
	}
	b.PutInt32(p.FileIndex)
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceFile) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFile#786c3b30 to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceFileTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceFile#786c3b30: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceFile) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFile#786c3b30 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode passportElementErrorSourceFile#786c3b30: field file_index: %w", err)
		}
		p.FileIndex = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementErrorSourceFile) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFile#786c3b30 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementErrorSourceFile")
	b.Comma()
	b.FieldStart("file_index")
	b.PutInt32(p.FileIndex)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceFile) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFile#786c3b30 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("passportElementErrorSourceFile"); err != nil {
				return fmt.Errorf("unable to decode passportElementErrorSourceFile#786c3b30: %w", err)
			}
		case "file_index":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode passportElementErrorSourceFile#786c3b30: field file_index: %w", err)
			}
			p.FileIndex = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetFileIndex returns value of FileIndex field.
func (p *PassportElementErrorSourceFile) GetFileIndex() (value int32) {
	if p == nil {
		return
	}
	return p.FileIndex
}

// PassportElementErrorSourceFiles represents TL type `passportElementErrorSourceFiles#70e6a6d2`.
type PassportElementErrorSourceFiles struct {
}

// PassportElementErrorSourceFilesTypeID is TL type id of PassportElementErrorSourceFiles.
const PassportElementErrorSourceFilesTypeID = 0x70e6a6d2

// construct implements constructor of PassportElementErrorSourceClass.
func (p PassportElementErrorSourceFiles) construct() PassportElementErrorSourceClass { return &p }

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

	_ PassportElementErrorSourceClass = &PassportElementErrorSourceFiles{}
)

func (p *PassportElementErrorSourceFiles) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PassportElementErrorSourceFiles) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFiles#70e6a6d2 as nil")
	}
	b.PutID(PassportElementErrorSourceFilesTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementErrorSourceFiles) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFiles#70e6a6d2 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PassportElementErrorSourceFiles) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFiles#70e6a6d2 to nil")
	}
	if err := b.ConsumeID(PassportElementErrorSourceFilesTypeID); err != nil {
		return fmt.Errorf("unable to decode passportElementErrorSourceFiles#70e6a6d2: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementErrorSourceFiles) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFiles#70e6a6d2 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementErrorSourceFiles) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementErrorSourceFiles#70e6a6d2 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementErrorSourceFiles")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PassportElementErrorSourceFiles) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementErrorSourceFiles#70e6a6d2 to nil")
	}

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

// PassportElementErrorSourceClassName is schema name of PassportElementErrorSourceClass.
const PassportElementErrorSourceClassName = "PassportElementErrorSource"

// PassportElementErrorSourceClass represents PassportElementErrorSource generic type.
//
// Example:
//
//	g, err := tdapi.DecodePassportElementErrorSource(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.PassportElementErrorSourceUnspecified: // passportElementErrorSourceUnspecified#e9734842
//	case *tdapi.PassportElementErrorSourceDataField: // passportElementErrorSourceDataField#ed9a5ce8
//	case *tdapi.PassportElementErrorSourceFrontSide: // passportElementErrorSourceFrontSide#70fd7334
//	case *tdapi.PassportElementErrorSourceReverseSide: // passportElementErrorSourceReverseSide#725bf9f7
//	case *tdapi.PassportElementErrorSourceSelfie: // passportElementErrorSourceSelfie#d07e1428
//	case *tdapi.PassportElementErrorSourceTranslationFile: // passportElementErrorSourceTranslationFile#d6e53714
//	case *tdapi.PassportElementErrorSourceTranslationFiles: // passportElementErrorSourceTranslationFiles#22a5a41c
//	case *tdapi.PassportElementErrorSourceFile: // passportElementErrorSourceFile#786c3b30
//	case *tdapi.PassportElementErrorSourceFiles: // passportElementErrorSourceFiles#70e6a6d2
//	default: panic(v)
//	}
type PassportElementErrorSourceClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PassportElementErrorSourceClass

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

// DecodePassportElementErrorSource implements binary de-serialization for PassportElementErrorSourceClass.
func DecodePassportElementErrorSource(buf *bin.Buffer) (PassportElementErrorSourceClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case PassportElementErrorSourceUnspecifiedTypeID:
		// Decoding passportElementErrorSourceUnspecified#e9734842.
		v := PassportElementErrorSourceUnspecified{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case PassportElementErrorSourceDataFieldTypeID:
		// Decoding passportElementErrorSourceDataField#ed9a5ce8.
		v := PassportElementErrorSourceDataField{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case PassportElementErrorSourceFrontSideTypeID:
		// Decoding passportElementErrorSourceFrontSide#70fd7334.
		v := PassportElementErrorSourceFrontSide{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case PassportElementErrorSourceReverseSideTypeID:
		// Decoding passportElementErrorSourceReverseSide#725bf9f7.
		v := PassportElementErrorSourceReverseSide{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case PassportElementErrorSourceSelfieTypeID:
		// Decoding passportElementErrorSourceSelfie#d07e1428.
		v := PassportElementErrorSourceSelfie{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case PassportElementErrorSourceTranslationFileTypeID:
		// Decoding passportElementErrorSourceTranslationFile#d6e53714.
		v := PassportElementErrorSourceTranslationFile{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case PassportElementErrorSourceTranslationFilesTypeID:
		// Decoding passportElementErrorSourceTranslationFiles#22a5a41c.
		v := PassportElementErrorSourceTranslationFiles{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case PassportElementErrorSourceFileTypeID:
		// Decoding passportElementErrorSourceFile#786c3b30.
		v := PassportElementErrorSourceFile{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case PassportElementErrorSourceFilesTypeID:
		// Decoding passportElementErrorSourceFiles#70e6a6d2.
		v := PassportElementErrorSourceFiles{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONPassportElementErrorSource implements binary de-serialization for PassportElementErrorSourceClass.
func DecodeTDLibJSONPassportElementErrorSource(buf tdjson.Decoder) (PassportElementErrorSourceClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "passportElementErrorSourceUnspecified":
		// Decoding passportElementErrorSourceUnspecified#e9734842.
		v := PassportElementErrorSourceUnspecified{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case "passportElementErrorSourceDataField":
		// Decoding passportElementErrorSourceDataField#ed9a5ce8.
		v := PassportElementErrorSourceDataField{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case "passportElementErrorSourceFrontSide":
		// Decoding passportElementErrorSourceFrontSide#70fd7334.
		v := PassportElementErrorSourceFrontSide{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case "passportElementErrorSourceReverseSide":
		// Decoding passportElementErrorSourceReverseSide#725bf9f7.
		v := PassportElementErrorSourceReverseSide{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case "passportElementErrorSourceSelfie":
		// Decoding passportElementErrorSourceSelfie#d07e1428.
		v := PassportElementErrorSourceSelfie{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case "passportElementErrorSourceTranslationFile":
		// Decoding passportElementErrorSourceTranslationFile#d6e53714.
		v := PassportElementErrorSourceTranslationFile{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case "passportElementErrorSourceTranslationFiles":
		// Decoding passportElementErrorSourceTranslationFiles#22a5a41c.
		v := PassportElementErrorSourceTranslationFiles{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case "passportElementErrorSourceFile":
		// Decoding passportElementErrorSourceFile#786c3b30.
		v := PassportElementErrorSourceFile{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	case "passportElementErrorSourceFiles":
		// Decoding passportElementErrorSourceFiles#70e6a6d2.
		v := PassportElementErrorSourceFiles{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PassportElementErrorSourceClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// PassportElementErrorSource boxes the PassportElementErrorSourceClass providing a helper.
type PassportElementErrorSourceBox struct {
	PassportElementErrorSource PassportElementErrorSourceClass
}

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

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

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

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