// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// PhoneCallDiscardReasonMissed represents TL type `phoneCallDiscardReasonMissed#85e42301`.
// The phone call was missed
//
// See https://core.telegram.org/constructor/phoneCallDiscardReasonMissed for reference.
type PhoneCallDiscardReasonMissed struct {
}

// PhoneCallDiscardReasonMissedTypeID is TL type id of PhoneCallDiscardReasonMissed.
const PhoneCallDiscardReasonMissedTypeID = 0x85e42301

// construct implements constructor of PhoneCallDiscardReasonClass.
func (p PhoneCallDiscardReasonMissed) construct() PhoneCallDiscardReasonClass { return &p }

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

	_ PhoneCallDiscardReasonClass = &PhoneCallDiscardReasonMissed{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PhoneCallDiscardReasonMissed) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode phoneCallDiscardReasonMissed#85e42301 as nil")
	}
	b.PutID(PhoneCallDiscardReasonMissedTypeID)
	return p.EncodeBare(b)
}

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

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

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

// PhoneCallDiscardReasonDisconnect represents TL type `phoneCallDiscardReasonDisconnect#e095c1a0`.
// The phone call was disconnected
//
// See https://core.telegram.org/constructor/phoneCallDiscardReasonDisconnect for reference.
type PhoneCallDiscardReasonDisconnect struct {
}

// PhoneCallDiscardReasonDisconnectTypeID is TL type id of PhoneCallDiscardReasonDisconnect.
const PhoneCallDiscardReasonDisconnectTypeID = 0xe095c1a0

// construct implements constructor of PhoneCallDiscardReasonClass.
func (p PhoneCallDiscardReasonDisconnect) construct() PhoneCallDiscardReasonClass { return &p }

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

	_ PhoneCallDiscardReasonClass = &PhoneCallDiscardReasonDisconnect{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PhoneCallDiscardReasonDisconnect) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode phoneCallDiscardReasonDisconnect#e095c1a0 as nil")
	}
	b.PutID(PhoneCallDiscardReasonDisconnectTypeID)
	return p.EncodeBare(b)
}

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

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

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

// PhoneCallDiscardReasonHangup represents TL type `phoneCallDiscardReasonHangup#57adc690`.
// The phone call was ended normally
//
// See https://core.telegram.org/constructor/phoneCallDiscardReasonHangup for reference.
type PhoneCallDiscardReasonHangup struct {
}

// PhoneCallDiscardReasonHangupTypeID is TL type id of PhoneCallDiscardReasonHangup.
const PhoneCallDiscardReasonHangupTypeID = 0x57adc690

// construct implements constructor of PhoneCallDiscardReasonClass.
func (p PhoneCallDiscardReasonHangup) construct() PhoneCallDiscardReasonClass { return &p }

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

	_ PhoneCallDiscardReasonClass = &PhoneCallDiscardReasonHangup{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PhoneCallDiscardReasonHangup) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode phoneCallDiscardReasonHangup#57adc690 as nil")
	}
	b.PutID(PhoneCallDiscardReasonHangupTypeID)
	return p.EncodeBare(b)
}

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

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

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

// PhoneCallDiscardReasonBusy represents TL type `phoneCallDiscardReasonBusy#faf7e8c9`.
// The phone call was discarded because the user is busy in another call
//
// See https://core.telegram.org/constructor/phoneCallDiscardReasonBusy for reference.
type PhoneCallDiscardReasonBusy struct {
}

// PhoneCallDiscardReasonBusyTypeID is TL type id of PhoneCallDiscardReasonBusy.
const PhoneCallDiscardReasonBusyTypeID = 0xfaf7e8c9

// construct implements constructor of PhoneCallDiscardReasonClass.
func (p PhoneCallDiscardReasonBusy) construct() PhoneCallDiscardReasonClass { return &p }

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

	_ PhoneCallDiscardReasonClass = &PhoneCallDiscardReasonBusy{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PhoneCallDiscardReasonBusy) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode phoneCallDiscardReasonBusy#faf7e8c9 as nil")
	}
	b.PutID(PhoneCallDiscardReasonBusyTypeID)
	return p.EncodeBare(b)
}

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

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

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

// PhoneCallDiscardReasonMigrateConferenceCall represents TL type `phoneCallDiscardReasonMigrateConferenceCall#9fbbf1f7`.
// This phone call was migrated to a conference call¹.
//
// Links:
//  1. https://core.telegram.org/api/end-to-end/group-calls
//
// See https://core.telegram.org/constructor/phoneCallDiscardReasonMigrateConferenceCall for reference.
type PhoneCallDiscardReasonMigrateConferenceCall struct {
	// Conference link »¹ slug.
	//
	// Links:
	//  1) https://core.telegram.org/api/links#conference-links
	Slug string
}

// PhoneCallDiscardReasonMigrateConferenceCallTypeID is TL type id of PhoneCallDiscardReasonMigrateConferenceCall.
const PhoneCallDiscardReasonMigrateConferenceCallTypeID = 0x9fbbf1f7

// construct implements constructor of PhoneCallDiscardReasonClass.
func (p PhoneCallDiscardReasonMigrateConferenceCall) construct() PhoneCallDiscardReasonClass {
	return &p
}

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

	_ PhoneCallDiscardReasonClass = &PhoneCallDiscardReasonMigrateConferenceCall{}
)

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

	return true
}

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

// FillFrom fills PhoneCallDiscardReasonMigrateConferenceCall from given interface.
func (p *PhoneCallDiscardReasonMigrateConferenceCall) FillFrom(from interface {
	GetSlug() (value string)
}) {
	p.Slug = from.GetSlug()
}

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

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

// TypeInfo returns info about TL type.
func (p *PhoneCallDiscardReasonMigrateConferenceCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "phoneCallDiscardReasonMigrateConferenceCall",
		ID:   PhoneCallDiscardReasonMigrateConferenceCallTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Slug",
			SchemaName: "slug",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PhoneCallDiscardReasonMigrateConferenceCall) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode phoneCallDiscardReasonMigrateConferenceCall#9fbbf1f7 as nil")
	}
	b.PutID(PhoneCallDiscardReasonMigrateConferenceCallTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PhoneCallDiscardReasonMigrateConferenceCall) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode phoneCallDiscardReasonMigrateConferenceCall#9fbbf1f7 as nil")
	}
	b.PutString(p.Slug)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PhoneCallDiscardReasonMigrateConferenceCall) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode phoneCallDiscardReasonMigrateConferenceCall#9fbbf1f7 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode phoneCallDiscardReasonMigrateConferenceCall#9fbbf1f7: field slug: %w", err)
		}
		p.Slug = value
	}
	return nil
}

// GetSlug returns value of Slug field.
func (p *PhoneCallDiscardReasonMigrateConferenceCall) GetSlug() (value string) {
	if p == nil {
		return
	}
	return p.Slug
}

// PhoneCallDiscardReasonClassName is schema name of PhoneCallDiscardReasonClass.
const PhoneCallDiscardReasonClassName = "PhoneCallDiscardReason"

// PhoneCallDiscardReasonClass represents PhoneCallDiscardReason generic type.
//
// See https://core.telegram.org/type/PhoneCallDiscardReason for reference.
//
// Example:
//
//	g, err := tg.DecodePhoneCallDiscardReason(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.PhoneCallDiscardReasonMissed: // phoneCallDiscardReasonMissed#85e42301
//	case *tg.PhoneCallDiscardReasonDisconnect: // phoneCallDiscardReasonDisconnect#e095c1a0
//	case *tg.PhoneCallDiscardReasonHangup: // phoneCallDiscardReasonHangup#57adc690
//	case *tg.PhoneCallDiscardReasonBusy: // phoneCallDiscardReasonBusy#faf7e8c9
//	case *tg.PhoneCallDiscardReasonMigrateConferenceCall: // phoneCallDiscardReasonMigrateConferenceCall#9fbbf1f7
//	default: panic(v)
//	}
type PhoneCallDiscardReasonClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PhoneCallDiscardReasonClass

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

// DecodePhoneCallDiscardReason implements binary de-serialization for PhoneCallDiscardReasonClass.
func DecodePhoneCallDiscardReason(buf *bin.Buffer) (PhoneCallDiscardReasonClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case PhoneCallDiscardReasonMissedTypeID:
		// Decoding phoneCallDiscardReasonMissed#85e42301.
		v := PhoneCallDiscardReasonMissed{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PhoneCallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case PhoneCallDiscardReasonDisconnectTypeID:
		// Decoding phoneCallDiscardReasonDisconnect#e095c1a0.
		v := PhoneCallDiscardReasonDisconnect{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PhoneCallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case PhoneCallDiscardReasonHangupTypeID:
		// Decoding phoneCallDiscardReasonHangup#57adc690.
		v := PhoneCallDiscardReasonHangup{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PhoneCallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case PhoneCallDiscardReasonBusyTypeID:
		// Decoding phoneCallDiscardReasonBusy#faf7e8c9.
		v := PhoneCallDiscardReasonBusy{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PhoneCallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case PhoneCallDiscardReasonMigrateConferenceCallTypeID:
		// Decoding phoneCallDiscardReasonMigrateConferenceCall#9fbbf1f7.
		v := PhoneCallDiscardReasonMigrateConferenceCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PhoneCallDiscardReasonClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PhoneCallDiscardReasonClass: %w", bin.NewUnexpectedID(id))
	}
}

// PhoneCallDiscardReason boxes the PhoneCallDiscardReasonClass providing a helper.
type PhoneCallDiscardReasonBox struct {
	PhoneCallDiscardReason PhoneCallDiscardReasonClass
}

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

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