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

// PassportElementPersonalDetails represents TL type `passportElementPersonalDetails#4894fe83`.
type PassportElementPersonalDetails struct {
	// Personal details of the user
	PersonalDetails PersonalDetails
}

// PassportElementPersonalDetailsTypeID is TL type id of PassportElementPersonalDetails.
const PassportElementPersonalDetailsTypeID = 0x4894fe83

// construct implements constructor of PassportElementClass.
func (p PassportElementPersonalDetails) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementPersonalDetails{}
)

func (p *PassportElementPersonalDetails) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.PersonalDetails.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementPersonalDetails) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementPersonalDetails",
		ID:   PassportElementPersonalDetailsTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "PersonalDetails",
			SchemaName: "personal_details",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementPersonalDetails) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPersonalDetails#4894fe83 as nil")
	}
	b.PutID(PassportElementPersonalDetailsTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementPersonalDetails) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPersonalDetails#4894fe83 as nil")
	}
	if err := p.PersonalDetails.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementPersonalDetails#4894fe83: field personal_details: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementPersonalDetails) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementPersonalDetails#4894fe83 to nil")
	}
	{
		if err := p.PersonalDetails.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementPersonalDetails#4894fe83: field personal_details: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementPersonalDetails) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPersonalDetails#4894fe83 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementPersonalDetails")
	b.Comma()
	b.FieldStart("personal_details")
	if err := p.PersonalDetails.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementPersonalDetails#4894fe83: field personal_details: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetPersonalDetails returns value of PersonalDetails field.
func (p *PassportElementPersonalDetails) GetPersonalDetails() (value PersonalDetails) {
	if p == nil {
		return
	}
	return p.PersonalDetails
}

// PassportElementPassport represents TL type `passportElementPassport#f043e723`.
type PassportElementPassport struct {
	// Passport
	Passport IdentityDocument
}

// PassportElementPassportTypeID is TL type id of PassportElementPassport.
const PassportElementPassportTypeID = 0xf043e723

// construct implements constructor of PassportElementClass.
func (p PassportElementPassport) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementPassport{}
)

func (p *PassportElementPassport) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.Passport.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementPassport) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementPassport",
		ID:   PassportElementPassportTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Passport",
			SchemaName: "passport",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementPassport) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPassport#f043e723 as nil")
	}
	b.PutID(PassportElementPassportTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementPassport) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPassport#f043e723 as nil")
	}
	if err := p.Passport.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementPassport#f043e723: field passport: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementPassport) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementPassport#f043e723 to nil")
	}
	{
		if err := p.Passport.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementPassport#f043e723: field passport: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementPassport) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPassport#f043e723 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementPassport")
	b.Comma()
	b.FieldStart("passport")
	if err := p.Passport.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementPassport#f043e723: field passport: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetPassport returns value of Passport field.
func (p *PassportElementPassport) GetPassport() (value IdentityDocument) {
	if p == nil {
		return
	}
	return p.Passport
}

// PassportElementDriverLicense represents TL type `passportElementDriverLicense#61f70cad`.
type PassportElementDriverLicense struct {
	// Driver license
	DriverLicense IdentityDocument
}

// PassportElementDriverLicenseTypeID is TL type id of PassportElementDriverLicense.
const PassportElementDriverLicenseTypeID = 0x61f70cad

// construct implements constructor of PassportElementClass.
func (p PassportElementDriverLicense) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementDriverLicense{}
)

func (p *PassportElementDriverLicense) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.DriverLicense.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementDriverLicense) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementDriverLicense",
		ID:   PassportElementDriverLicenseTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DriverLicense",
			SchemaName: "driver_license",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementDriverLicense) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementDriverLicense#61f70cad as nil")
	}
	b.PutID(PassportElementDriverLicenseTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementDriverLicense) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementDriverLicense#61f70cad as nil")
	}
	if err := p.DriverLicense.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementDriverLicense#61f70cad: field driver_license: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementDriverLicense) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementDriverLicense#61f70cad to nil")
	}
	{
		if err := p.DriverLicense.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementDriverLicense#61f70cad: field driver_license: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementDriverLicense) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementDriverLicense#61f70cad as nil")
	}
	b.ObjStart()
	b.PutID("passportElementDriverLicense")
	b.Comma()
	b.FieldStart("driver_license")
	if err := p.DriverLicense.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementDriverLicense#61f70cad: field driver_license: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetDriverLicense returns value of DriverLicense field.
func (p *PassportElementDriverLicense) GetDriverLicense() (value IdentityDocument) {
	if p == nil {
		return
	}
	return p.DriverLicense
}

// PassportElementIdentityCard represents TL type `passportElementIdentityCard#7c33e535`.
type PassportElementIdentityCard struct {
	// Identity card
	IdentityCard IdentityDocument
}

// PassportElementIdentityCardTypeID is TL type id of PassportElementIdentityCard.
const PassportElementIdentityCardTypeID = 0x7c33e535

// construct implements constructor of PassportElementClass.
func (p PassportElementIdentityCard) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementIdentityCard{}
)

func (p *PassportElementIdentityCard) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.IdentityCard.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementIdentityCard) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementIdentityCard",
		ID:   PassportElementIdentityCardTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "IdentityCard",
			SchemaName: "identity_card",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementIdentityCard) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementIdentityCard#7c33e535 as nil")
	}
	b.PutID(PassportElementIdentityCardTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementIdentityCard) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementIdentityCard#7c33e535 as nil")
	}
	if err := p.IdentityCard.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementIdentityCard#7c33e535: field identity_card: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementIdentityCard) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementIdentityCard#7c33e535 to nil")
	}
	{
		if err := p.IdentityCard.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementIdentityCard#7c33e535: field identity_card: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementIdentityCard) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementIdentityCard#7c33e535 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementIdentityCard")
	b.Comma()
	b.FieldStart("identity_card")
	if err := p.IdentityCard.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementIdentityCard#7c33e535: field identity_card: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetIdentityCard returns value of IdentityCard field.
func (p *PassportElementIdentityCard) GetIdentityCard() (value IdentityDocument) {
	if p == nil {
		return
	}
	return p.IdentityCard
}

// PassportElementInternalPassport represents TL type `passportElementInternalPassport#228ad87`.
type PassportElementInternalPassport struct {
	// Internal passport
	InternalPassport IdentityDocument
}

// PassportElementInternalPassportTypeID is TL type id of PassportElementInternalPassport.
const PassportElementInternalPassportTypeID = 0x228ad87

// construct implements constructor of PassportElementClass.
func (p PassportElementInternalPassport) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementInternalPassport{}
)

func (p *PassportElementInternalPassport) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.InternalPassport.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementInternalPassport) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementInternalPassport",
		ID:   PassportElementInternalPassportTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "InternalPassport",
			SchemaName: "internal_passport",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementInternalPassport) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementInternalPassport#228ad87 as nil")
	}
	b.PutID(PassportElementInternalPassportTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementInternalPassport) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementInternalPassport#228ad87 as nil")
	}
	if err := p.InternalPassport.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementInternalPassport#228ad87: field internal_passport: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementInternalPassport) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementInternalPassport#228ad87 to nil")
	}
	{
		if err := p.InternalPassport.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementInternalPassport#228ad87: field internal_passport: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementInternalPassport) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementInternalPassport#228ad87 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementInternalPassport")
	b.Comma()
	b.FieldStart("internal_passport")
	if err := p.InternalPassport.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementInternalPassport#228ad87: field internal_passport: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetInternalPassport returns value of InternalPassport field.
func (p *PassportElementInternalPassport) GetInternalPassport() (value IdentityDocument) {
	if p == nil {
		return
	}
	return p.InternalPassport
}

// PassportElementAddress represents TL type `passportElementAddress#d15a1630`.
type PassportElementAddress struct {
	// Address
	Address Address
}

// PassportElementAddressTypeID is TL type id of PassportElementAddress.
const PassportElementAddressTypeID = 0xd15a1630

// construct implements constructor of PassportElementClass.
func (p PassportElementAddress) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementAddress{}
)

func (p *PassportElementAddress) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.Address.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementAddress) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementAddress",
		ID:   PassportElementAddressTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Address",
			SchemaName: "address",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementAddress) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementAddress#d15a1630 as nil")
	}
	b.PutID(PassportElementAddressTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementAddress) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementAddress#d15a1630 as nil")
	}
	if err := p.Address.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementAddress#d15a1630: field address: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementAddress) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementAddress#d15a1630 to nil")
	}
	{
		if err := p.Address.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementAddress#d15a1630: field address: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementAddress) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementAddress#d15a1630 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementAddress")
	b.Comma()
	b.FieldStart("address")
	if err := p.Address.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementAddress#d15a1630: field address: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetAddress returns value of Address field.
func (p *PassportElementAddress) GetAddress() (value Address) {
	if p == nil {
		return
	}
	return p.Address
}

// PassportElementUtilityBill represents TL type `passportElementUtilityBill#f2041dd2`.
type PassportElementUtilityBill struct {
	// Utility bill
	UtilityBill PersonalDocument
}

// PassportElementUtilityBillTypeID is TL type id of PassportElementUtilityBill.
const PassportElementUtilityBillTypeID = 0xf2041dd2

// construct implements constructor of PassportElementClass.
func (p PassportElementUtilityBill) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementUtilityBill{}
)

func (p *PassportElementUtilityBill) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.UtilityBill.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementUtilityBill) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementUtilityBill",
		ID:   PassportElementUtilityBillTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UtilityBill",
			SchemaName: "utility_bill",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementUtilityBill) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementUtilityBill#f2041dd2 as nil")
	}
	b.PutID(PassportElementUtilityBillTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementUtilityBill) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementUtilityBill#f2041dd2 as nil")
	}
	if err := p.UtilityBill.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementUtilityBill#f2041dd2: field utility_bill: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementUtilityBill) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementUtilityBill#f2041dd2 to nil")
	}
	{
		if err := p.UtilityBill.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementUtilityBill#f2041dd2: field utility_bill: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementUtilityBill) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementUtilityBill#f2041dd2 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementUtilityBill")
	b.Comma()
	b.FieldStart("utility_bill")
	if err := p.UtilityBill.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementUtilityBill#f2041dd2: field utility_bill: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetUtilityBill returns value of UtilityBill field.
func (p *PassportElementUtilityBill) GetUtilityBill() (value PersonalDocument) {
	if p == nil {
		return
	}
	return p.UtilityBill
}

// PassportElementBankStatement represents TL type `passportElementBankStatement#ea283268`.
type PassportElementBankStatement struct {
	// Bank statement
	BankStatement PersonalDocument
}

// PassportElementBankStatementTypeID is TL type id of PassportElementBankStatement.
const PassportElementBankStatementTypeID = 0xea283268

// construct implements constructor of PassportElementClass.
func (p PassportElementBankStatement) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementBankStatement{}
)

func (p *PassportElementBankStatement) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.BankStatement.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementBankStatement) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementBankStatement",
		ID:   PassportElementBankStatementTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BankStatement",
			SchemaName: "bank_statement",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementBankStatement) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementBankStatement#ea283268 as nil")
	}
	b.PutID(PassportElementBankStatementTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementBankStatement) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementBankStatement#ea283268 as nil")
	}
	if err := p.BankStatement.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementBankStatement#ea283268: field bank_statement: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementBankStatement) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementBankStatement#ea283268 to nil")
	}
	{
		if err := p.BankStatement.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementBankStatement#ea283268: field bank_statement: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementBankStatement) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementBankStatement#ea283268 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementBankStatement")
	b.Comma()
	b.FieldStart("bank_statement")
	if err := p.BankStatement.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementBankStatement#ea283268: field bank_statement: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetBankStatement returns value of BankStatement field.
func (p *PassportElementBankStatement) GetBankStatement() (value PersonalDocument) {
	if p == nil {
		return
	}
	return p.BankStatement
}

// PassportElementRentalAgreement represents TL type `passportElementRentalAgreement#eeb4cb28`.
type PassportElementRentalAgreement struct {
	// Rental agreement
	RentalAgreement PersonalDocument
}

// PassportElementRentalAgreementTypeID is TL type id of PassportElementRentalAgreement.
const PassportElementRentalAgreementTypeID = 0xeeb4cb28

// construct implements constructor of PassportElementClass.
func (p PassportElementRentalAgreement) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementRentalAgreement{}
)

func (p *PassportElementRentalAgreement) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.RentalAgreement.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementRentalAgreement) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementRentalAgreement",
		ID:   PassportElementRentalAgreementTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "RentalAgreement",
			SchemaName: "rental_agreement",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementRentalAgreement) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementRentalAgreement#eeb4cb28 as nil")
	}
	b.PutID(PassportElementRentalAgreementTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementRentalAgreement) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementRentalAgreement#eeb4cb28 as nil")
	}
	if err := p.RentalAgreement.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementRentalAgreement#eeb4cb28: field rental_agreement: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementRentalAgreement) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementRentalAgreement#eeb4cb28 to nil")
	}
	{
		if err := p.RentalAgreement.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementRentalAgreement#eeb4cb28: field rental_agreement: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementRentalAgreement) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementRentalAgreement#eeb4cb28 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementRentalAgreement")
	b.Comma()
	b.FieldStart("rental_agreement")
	if err := p.RentalAgreement.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementRentalAgreement#eeb4cb28: field rental_agreement: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetRentalAgreement returns value of RentalAgreement field.
func (p *PassportElementRentalAgreement) GetRentalAgreement() (value PersonalDocument) {
	if p == nil {
		return
	}
	return p.RentalAgreement
}

// PassportElementPassportRegistration represents TL type `passportElementPassportRegistration#24dadc7f`.
type PassportElementPassportRegistration struct {
	// Passport registration pages
	PassportRegistration PersonalDocument
}

// PassportElementPassportRegistrationTypeID is TL type id of PassportElementPassportRegistration.
const PassportElementPassportRegistrationTypeID = 0x24dadc7f

// construct implements constructor of PassportElementClass.
func (p PassportElementPassportRegistration) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementPassportRegistration{}
)

func (p *PassportElementPassportRegistration) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.PassportRegistration.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementPassportRegistration) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementPassportRegistration",
		ID:   PassportElementPassportRegistrationTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "PassportRegistration",
			SchemaName: "passport_registration",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementPassportRegistration) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPassportRegistration#24dadc7f as nil")
	}
	b.PutID(PassportElementPassportRegistrationTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementPassportRegistration) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPassportRegistration#24dadc7f as nil")
	}
	if err := p.PassportRegistration.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementPassportRegistration#24dadc7f: field passport_registration: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementPassportRegistration) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementPassportRegistration#24dadc7f to nil")
	}
	{
		if err := p.PassportRegistration.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementPassportRegistration#24dadc7f: field passport_registration: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementPassportRegistration) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPassportRegistration#24dadc7f as nil")
	}
	b.ObjStart()
	b.PutID("passportElementPassportRegistration")
	b.Comma()
	b.FieldStart("passport_registration")
	if err := p.PassportRegistration.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementPassportRegistration#24dadc7f: field passport_registration: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetPassportRegistration returns value of PassportRegistration field.
func (p *PassportElementPassportRegistration) GetPassportRegistration() (value PersonalDocument) {
	if p == nil {
		return
	}
	return p.PassportRegistration
}

// PassportElementTemporaryRegistration represents TL type `passportElementTemporaryRegistration#49c4aff0`.
type PassportElementTemporaryRegistration struct {
	// Temporary registration
	TemporaryRegistration PersonalDocument
}

// PassportElementTemporaryRegistrationTypeID is TL type id of PassportElementTemporaryRegistration.
const PassportElementTemporaryRegistrationTypeID = 0x49c4aff0

// construct implements constructor of PassportElementClass.
func (p PassportElementTemporaryRegistration) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementTemporaryRegistration{}
)

func (p *PassportElementTemporaryRegistration) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.TemporaryRegistration.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementTemporaryRegistration) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementTemporaryRegistration",
		ID:   PassportElementTemporaryRegistrationTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "TemporaryRegistration",
			SchemaName: "temporary_registration",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementTemporaryRegistration) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementTemporaryRegistration#49c4aff0 as nil")
	}
	b.PutID(PassportElementTemporaryRegistrationTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementTemporaryRegistration) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementTemporaryRegistration#49c4aff0 as nil")
	}
	if err := p.TemporaryRegistration.Encode(b); err != nil {
		return fmt.Errorf("unable to encode passportElementTemporaryRegistration#49c4aff0: field temporary_registration: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementTemporaryRegistration) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementTemporaryRegistration#49c4aff0 to nil")
	}
	{
		if err := p.TemporaryRegistration.Decode(b); err != nil {
			return fmt.Errorf("unable to decode passportElementTemporaryRegistration#49c4aff0: field temporary_registration: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementTemporaryRegistration) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementTemporaryRegistration#49c4aff0 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementTemporaryRegistration")
	b.Comma()
	b.FieldStart("temporary_registration")
	if err := p.TemporaryRegistration.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode passportElementTemporaryRegistration#49c4aff0: field temporary_registration: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetTemporaryRegistration returns value of TemporaryRegistration field.
func (p *PassportElementTemporaryRegistration) GetTemporaryRegistration() (value PersonalDocument) {
	if p == nil {
		return
	}
	return p.TemporaryRegistration
}

// PassportElementPhoneNumber represents TL type `passportElementPhoneNumber#b1509799`.
type PassportElementPhoneNumber struct {
	// Phone number
	PhoneNumber string
}

// PassportElementPhoneNumberTypeID is TL type id of PassportElementPhoneNumber.
const PassportElementPhoneNumberTypeID = 0xb1509799

// construct implements constructor of PassportElementClass.
func (p PassportElementPhoneNumber) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementPhoneNumber{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementPhoneNumber) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementPhoneNumber",
		ID:   PassportElementPhoneNumberTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "PhoneNumber",
			SchemaName: "phone_number",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementPhoneNumber) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPhoneNumber#b1509799 as nil")
	}
	b.PutID(PassportElementPhoneNumberTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementPhoneNumber) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPhoneNumber#b1509799 as nil")
	}
	b.PutString(p.PhoneNumber)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementPhoneNumber) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementPhoneNumber#b1509799 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode passportElementPhoneNumber#b1509799: field phone_number: %w", err)
		}
		p.PhoneNumber = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementPhoneNumber) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementPhoneNumber#b1509799 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementPhoneNumber")
	b.Comma()
	b.FieldStart("phone_number")
	b.PutString(p.PhoneNumber)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetPhoneNumber returns value of PhoneNumber field.
func (p *PassportElementPhoneNumber) GetPhoneNumber() (value string) {
	if p == nil {
		return
	}
	return p.PhoneNumber
}

// PassportElementEmailAddress represents TL type `passportElementEmailAddress#a4ea9805`.
type PassportElementEmailAddress struct {
	// Email address
	EmailAddress string
}

// PassportElementEmailAddressTypeID is TL type id of PassportElementEmailAddress.
const PassportElementEmailAddressTypeID = 0xa4ea9805

// construct implements constructor of PassportElementClass.
func (p PassportElementEmailAddress) construct() PassportElementClass { return &p }

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

	_ PassportElementClass = &PassportElementEmailAddress{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PassportElementEmailAddress) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "passportElementEmailAddress",
		ID:   PassportElementEmailAddressTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "EmailAddress",
			SchemaName: "email_address",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PassportElementEmailAddress) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementEmailAddress#a4ea9805 as nil")
	}
	b.PutID(PassportElementEmailAddressTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PassportElementEmailAddress) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementEmailAddress#a4ea9805 as nil")
	}
	b.PutString(p.EmailAddress)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PassportElementEmailAddress) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode passportElementEmailAddress#a4ea9805 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode passportElementEmailAddress#a4ea9805: field email_address: %w", err)
		}
		p.EmailAddress = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PassportElementEmailAddress) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode passportElementEmailAddress#a4ea9805 as nil")
	}
	b.ObjStart()
	b.PutID("passportElementEmailAddress")
	b.Comma()
	b.FieldStart("email_address")
	b.PutString(p.EmailAddress)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetEmailAddress returns value of EmailAddress field.
func (p *PassportElementEmailAddress) GetEmailAddress() (value string) {
	if p == nil {
		return
	}
	return p.EmailAddress
}

// PassportElementClassName is schema name of PassportElementClass.
const PassportElementClassName = "PassportElement"

// PassportElementClass represents PassportElement generic type.
//
// Example:
//
//	g, err := tdapi.DecodePassportElement(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.PassportElementPersonalDetails: // passportElementPersonalDetails#4894fe83
//	case *tdapi.PassportElementPassport: // passportElementPassport#f043e723
//	case *tdapi.PassportElementDriverLicense: // passportElementDriverLicense#61f70cad
//	case *tdapi.PassportElementIdentityCard: // passportElementIdentityCard#7c33e535
//	case *tdapi.PassportElementInternalPassport: // passportElementInternalPassport#228ad87
//	case *tdapi.PassportElementAddress: // passportElementAddress#d15a1630
//	case *tdapi.PassportElementUtilityBill: // passportElementUtilityBill#f2041dd2
//	case *tdapi.PassportElementBankStatement: // passportElementBankStatement#ea283268
//	case *tdapi.PassportElementRentalAgreement: // passportElementRentalAgreement#eeb4cb28
//	case *tdapi.PassportElementPassportRegistration: // passportElementPassportRegistration#24dadc7f
//	case *tdapi.PassportElementTemporaryRegistration: // passportElementTemporaryRegistration#49c4aff0
//	case *tdapi.PassportElementPhoneNumber: // passportElementPhoneNumber#b1509799
//	case *tdapi.PassportElementEmailAddress: // passportElementEmailAddress#a4ea9805
//	default: panic(v)
//	}
type PassportElementClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PassportElementClass

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

// DecodePassportElement implements binary de-serialization for PassportElementClass.
func DecodePassportElement(buf *bin.Buffer) (PassportElementClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case PassportElementPersonalDetailsTypeID:
		// Decoding passportElementPersonalDetails#4894fe83.
		v := PassportElementPersonalDetails{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementPassportTypeID:
		// Decoding passportElementPassport#f043e723.
		v := PassportElementPassport{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementDriverLicenseTypeID:
		// Decoding passportElementDriverLicense#61f70cad.
		v := PassportElementDriverLicense{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementIdentityCardTypeID:
		// Decoding passportElementIdentityCard#7c33e535.
		v := PassportElementIdentityCard{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementInternalPassportTypeID:
		// Decoding passportElementInternalPassport#228ad87.
		v := PassportElementInternalPassport{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementAddressTypeID:
		// Decoding passportElementAddress#d15a1630.
		v := PassportElementAddress{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementUtilityBillTypeID:
		// Decoding passportElementUtilityBill#f2041dd2.
		v := PassportElementUtilityBill{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementBankStatementTypeID:
		// Decoding passportElementBankStatement#ea283268.
		v := PassportElementBankStatement{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementRentalAgreementTypeID:
		// Decoding passportElementRentalAgreement#eeb4cb28.
		v := PassportElementRentalAgreement{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementPassportRegistrationTypeID:
		// Decoding passportElementPassportRegistration#24dadc7f.
		v := PassportElementPassportRegistration{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementTemporaryRegistrationTypeID:
		// Decoding passportElementTemporaryRegistration#49c4aff0.
		v := PassportElementTemporaryRegistration{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementPhoneNumberTypeID:
		// Decoding passportElementPhoneNumber#b1509799.
		v := PassportElementPhoneNumber{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case PassportElementEmailAddressTypeID:
		// Decoding passportElementEmailAddress#a4ea9805.
		v := PassportElementEmailAddress{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PassportElementClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONPassportElement implements binary de-serialization for PassportElementClass.
func DecodeTDLibJSONPassportElement(buf tdjson.Decoder) (PassportElementClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "passportElementPersonalDetails":
		// Decoding passportElementPersonalDetails#4894fe83.
		v := PassportElementPersonalDetails{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementPassport":
		// Decoding passportElementPassport#f043e723.
		v := PassportElementPassport{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementDriverLicense":
		// Decoding passportElementDriverLicense#61f70cad.
		v := PassportElementDriverLicense{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementIdentityCard":
		// Decoding passportElementIdentityCard#7c33e535.
		v := PassportElementIdentityCard{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementInternalPassport":
		// Decoding passportElementInternalPassport#228ad87.
		v := PassportElementInternalPassport{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementAddress":
		// Decoding passportElementAddress#d15a1630.
		v := PassportElementAddress{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementUtilityBill":
		// Decoding passportElementUtilityBill#f2041dd2.
		v := PassportElementUtilityBill{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementBankStatement":
		// Decoding passportElementBankStatement#ea283268.
		v := PassportElementBankStatement{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementRentalAgreement":
		// Decoding passportElementRentalAgreement#eeb4cb28.
		v := PassportElementRentalAgreement{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementPassportRegistration":
		// Decoding passportElementPassportRegistration#24dadc7f.
		v := PassportElementPassportRegistration{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementTemporaryRegistration":
		// Decoding passportElementTemporaryRegistration#49c4aff0.
		v := PassportElementTemporaryRegistration{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementPhoneNumber":
		// Decoding passportElementPhoneNumber#b1509799.
		v := PassportElementPhoneNumber{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	case "passportElementEmailAddress":
		// Decoding passportElementEmailAddress#a4ea9805.
		v := PassportElementEmailAddress{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PassportElementClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PassportElementClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// PassportElement boxes the PassportElementClass providing a helper.
type PassportElementBox struct {
	PassportElement PassportElementClass
}

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

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

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

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