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

// CallDiscardReasonEmpty represents TL type `callDiscardReasonEmpty#b4f66fc3`.
type CallDiscardReasonEmpty struct {
}

// CallDiscardReasonEmptyTypeID is TL type id of CallDiscardReasonEmpty.
const CallDiscardReasonEmptyTypeID = 0xb4f66fc3

// construct implements constructor of CallDiscardReasonClass.
func (c CallDiscardReasonEmpty) construct() CallDiscardReasonClass { return &c }

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

	_ CallDiscardReasonClass = &CallDiscardReasonEmpty{}
)

func (c *CallDiscardReasonEmpty) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CallDiscardReasonEmpty) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonEmpty#b4f66fc3 as nil")
	}
	b.PutID(CallDiscardReasonEmptyTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CallDiscardReasonEmpty) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonEmpty#b4f66fc3 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CallDiscardReasonEmpty) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonEmpty#b4f66fc3 to nil")
	}
	if err := b.ConsumeID(CallDiscardReasonEmptyTypeID); err != nil {
		return fmt.Errorf("unable to decode callDiscardReasonEmpty#b4f66fc3: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CallDiscardReasonEmpty) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonEmpty#b4f66fc3 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CallDiscardReasonEmpty) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonEmpty#b4f66fc3 to nil")
	}

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

// CallDiscardReasonMissed represents TL type `callDiscardReasonMissed#64283a7c`.
type CallDiscardReasonMissed struct {
}

// CallDiscardReasonMissedTypeID is TL type id of CallDiscardReasonMissed.
const CallDiscardReasonMissedTypeID = 0x64283a7c

// construct implements constructor of CallDiscardReasonClass.
func (c CallDiscardReasonMissed) construct() CallDiscardReasonClass { return &c }

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

	_ CallDiscardReasonClass = &CallDiscardReasonMissed{}
)

func (c *CallDiscardReasonMissed) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CallDiscardReasonMissed) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonMissed#64283a7c as nil")
	}
	b.PutID(CallDiscardReasonMissedTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CallDiscardReasonMissed) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonMissed#64283a7c as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CallDiscardReasonMissed) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonMissed#64283a7c to nil")
	}
	if err := b.ConsumeID(CallDiscardReasonMissedTypeID); err != nil {
		return fmt.Errorf("unable to decode callDiscardReasonMissed#64283a7c: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CallDiscardReasonMissed) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonMissed#64283a7c to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CallDiscardReasonMissed) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonMissed#64283a7c as nil")
	}
	b.ObjStart()
	b.PutID("callDiscardReasonMissed")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CallDiscardReasonMissed) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonMissed#64283a7c to nil")
	}

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

// CallDiscardReasonDeclined represents TL type `callDiscardReasonDeclined#98e36c32`.
type CallDiscardReasonDeclined struct {
}

// CallDiscardReasonDeclinedTypeID is TL type id of CallDiscardReasonDeclined.
const CallDiscardReasonDeclinedTypeID = 0x98e36c32

// construct implements constructor of CallDiscardReasonClass.
func (c CallDiscardReasonDeclined) construct() CallDiscardReasonClass { return &c }

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

	_ CallDiscardReasonClass = &CallDiscardReasonDeclined{}
)

func (c *CallDiscardReasonDeclined) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CallDiscardReasonDeclined) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonDeclined#98e36c32 as nil")
	}
	b.PutID(CallDiscardReasonDeclinedTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CallDiscardReasonDeclined) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonDeclined#98e36c32 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CallDiscardReasonDeclined) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonDeclined#98e36c32 to nil")
	}
	if err := b.ConsumeID(CallDiscardReasonDeclinedTypeID); err != nil {
		return fmt.Errorf("unable to decode callDiscardReasonDeclined#98e36c32: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CallDiscardReasonDeclined) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonDeclined#98e36c32 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CallDiscardReasonDeclined) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonDeclined#98e36c32 as nil")
	}
	b.ObjStart()
	b.PutID("callDiscardReasonDeclined")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CallDiscardReasonDeclined) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonDeclined#98e36c32 to nil")
	}

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

// CallDiscardReasonDisconnected represents TL type `callDiscardReasonDisconnected#aff563a2`.
type CallDiscardReasonDisconnected struct {
}

// CallDiscardReasonDisconnectedTypeID is TL type id of CallDiscardReasonDisconnected.
const CallDiscardReasonDisconnectedTypeID = 0xaff563a2

// construct implements constructor of CallDiscardReasonClass.
func (c CallDiscardReasonDisconnected) construct() CallDiscardReasonClass { return &c }

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

	_ CallDiscardReasonClass = &CallDiscardReasonDisconnected{}
)

func (c *CallDiscardReasonDisconnected) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CallDiscardReasonDisconnected) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonDisconnected#aff563a2 as nil")
	}
	b.PutID(CallDiscardReasonDisconnectedTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CallDiscardReasonDisconnected) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonDisconnected#aff563a2 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CallDiscardReasonDisconnected) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonDisconnected#aff563a2 to nil")
	}
	if err := b.ConsumeID(CallDiscardReasonDisconnectedTypeID); err != nil {
		return fmt.Errorf("unable to decode callDiscardReasonDisconnected#aff563a2: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CallDiscardReasonDisconnected) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonDisconnected#aff563a2 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CallDiscardReasonDisconnected) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonDisconnected#aff563a2 to nil")
	}

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

// CallDiscardReasonHungUp represents TL type `callDiscardReasonHungUp#1a1ea5e6`.
type CallDiscardReasonHungUp struct {
}

// CallDiscardReasonHungUpTypeID is TL type id of CallDiscardReasonHungUp.
const CallDiscardReasonHungUpTypeID = 0x1a1ea5e6

// construct implements constructor of CallDiscardReasonClass.
func (c CallDiscardReasonHungUp) construct() CallDiscardReasonClass { return &c }

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

	_ CallDiscardReasonClass = &CallDiscardReasonHungUp{}
)

func (c *CallDiscardReasonHungUp) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CallDiscardReasonHungUp) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonHungUp#1a1ea5e6 as nil")
	}
	b.PutID(CallDiscardReasonHungUpTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CallDiscardReasonHungUp) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonHungUp#1a1ea5e6 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CallDiscardReasonHungUp) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonHungUp#1a1ea5e6 to nil")
	}
	if err := b.ConsumeID(CallDiscardReasonHungUpTypeID); err != nil {
		return fmt.Errorf("unable to decode callDiscardReasonHungUp#1a1ea5e6: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CallDiscardReasonHungUp) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonHungUp#1a1ea5e6 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CallDiscardReasonHungUp) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonHungUp#1a1ea5e6 as nil")
	}
	b.ObjStart()
	b.PutID("callDiscardReasonHungUp")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CallDiscardReasonHungUp) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonHungUp#1a1ea5e6 to nil")
	}

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

// CallDiscardReasonUpgradeToGroupCall represents TL type `callDiscardReasonUpgradeToGroupCall#4ac64b07`.
type CallDiscardReasonUpgradeToGroupCall struct {
	// Invite link for the group call
	InviteLink string
}

// CallDiscardReasonUpgradeToGroupCallTypeID is TL type id of CallDiscardReasonUpgradeToGroupCall.
const CallDiscardReasonUpgradeToGroupCallTypeID = 0x4ac64b07

// construct implements constructor of CallDiscardReasonClass.
func (c CallDiscardReasonUpgradeToGroupCall) construct() CallDiscardReasonClass { return &c }

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

	_ CallDiscardReasonClass = &CallDiscardReasonUpgradeToGroupCall{}
)

func (c *CallDiscardReasonUpgradeToGroupCall) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.InviteLink == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CallDiscardReasonUpgradeToGroupCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "callDiscardReasonUpgradeToGroupCall",
		ID:   CallDiscardReasonUpgradeToGroupCallTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "InviteLink",
			SchemaName: "invite_link",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CallDiscardReasonUpgradeToGroupCall) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonUpgradeToGroupCall#4ac64b07 as nil")
	}
	b.PutID(CallDiscardReasonUpgradeToGroupCallTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CallDiscardReasonUpgradeToGroupCall) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonUpgradeToGroupCall#4ac64b07 as nil")
	}
	b.PutString(c.InviteLink)
	return nil
}

// Decode implements bin.Decoder.
func (c *CallDiscardReasonUpgradeToGroupCall) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonUpgradeToGroupCall#4ac64b07 to nil")
	}
	if err := b.ConsumeID(CallDiscardReasonUpgradeToGroupCallTypeID); err != nil {
		return fmt.Errorf("unable to decode callDiscardReasonUpgradeToGroupCall#4ac64b07: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CallDiscardReasonUpgradeToGroupCall) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonUpgradeToGroupCall#4ac64b07 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode callDiscardReasonUpgradeToGroupCall#4ac64b07: field invite_link: %w", err)
		}
		c.InviteLink = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CallDiscardReasonUpgradeToGroupCall) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode callDiscardReasonUpgradeToGroupCall#4ac64b07 as nil")
	}
	b.ObjStart()
	b.PutID("callDiscardReasonUpgradeToGroupCall")
	b.Comma()
	b.FieldStart("invite_link")
	b.PutString(c.InviteLink)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CallDiscardReasonUpgradeToGroupCall) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode callDiscardReasonUpgradeToGroupCall#4ac64b07 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("callDiscardReasonUpgradeToGroupCall"); err != nil {
				return fmt.Errorf("unable to decode callDiscardReasonUpgradeToGroupCall#4ac64b07: %w", err)
			}
		case "invite_link":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode callDiscardReasonUpgradeToGroupCall#4ac64b07: field invite_link: %w", err)
			}
			c.InviteLink = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetInviteLink returns value of InviteLink field.
func (c *CallDiscardReasonUpgradeToGroupCall) GetInviteLink() (value string) {
	if c == nil {
		return
	}
	return c.InviteLink
}

// CallDiscardReasonClassName is schema name of CallDiscardReasonClass.
const CallDiscardReasonClassName = "CallDiscardReason"

// CallDiscardReasonClass represents CallDiscardReason generic type.
//
// Example:
//
//	g, err := tdapi.DecodeCallDiscardReason(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.CallDiscardReasonEmpty: // callDiscardReasonEmpty#b4f66fc3
//	case *tdapi.CallDiscardReasonMissed: // callDiscardReasonMissed#64283a7c
//	case *tdapi.CallDiscardReasonDeclined: // callDiscardReasonDeclined#98e36c32
//	case *tdapi.CallDiscardReasonDisconnected: // callDiscardReasonDisconnected#aff563a2
//	case *tdapi.CallDiscardReasonHungUp: // callDiscardReasonHungUp#1a1ea5e6
//	case *tdapi.CallDiscardReasonUpgradeToGroupCall: // callDiscardReasonUpgradeToGroupCall#4ac64b07
//	default: panic(v)
//	}
type CallDiscardReasonClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() CallDiscardReasonClass

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

// DecodeCallDiscardReason implements binary de-serialization for CallDiscardReasonClass.
func DecodeCallDiscardReason(buf *bin.Buffer) (CallDiscardReasonClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case CallDiscardReasonEmptyTypeID:
		// Decoding callDiscardReasonEmpty#b4f66fc3.
		v := CallDiscardReasonEmpty{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case CallDiscardReasonMissedTypeID:
		// Decoding callDiscardReasonMissed#64283a7c.
		v := CallDiscardReasonMissed{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case CallDiscardReasonDeclinedTypeID:
		// Decoding callDiscardReasonDeclined#98e36c32.
		v := CallDiscardReasonDeclined{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case CallDiscardReasonDisconnectedTypeID:
		// Decoding callDiscardReasonDisconnected#aff563a2.
		v := CallDiscardReasonDisconnected{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case CallDiscardReasonHungUpTypeID:
		// Decoding callDiscardReasonHungUp#1a1ea5e6.
		v := CallDiscardReasonHungUp{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case CallDiscardReasonUpgradeToGroupCallTypeID:
		// Decoding callDiscardReasonUpgradeToGroupCall#4ac64b07.
		v := CallDiscardReasonUpgradeToGroupCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONCallDiscardReason implements binary de-serialization for CallDiscardReasonClass.
func DecodeTDLibJSONCallDiscardReason(buf tdjson.Decoder) (CallDiscardReasonClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "callDiscardReasonEmpty":
		// Decoding callDiscardReasonEmpty#b4f66fc3.
		v := CallDiscardReasonEmpty{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case "callDiscardReasonMissed":
		// Decoding callDiscardReasonMissed#64283a7c.
		v := CallDiscardReasonMissed{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case "callDiscardReasonDeclined":
		// Decoding callDiscardReasonDeclined#98e36c32.
		v := CallDiscardReasonDeclined{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case "callDiscardReasonDisconnected":
		// Decoding callDiscardReasonDisconnected#aff563a2.
		v := CallDiscardReasonDisconnected{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case "callDiscardReasonHungUp":
		// Decoding callDiscardReasonHungUp#1a1ea5e6.
		v := CallDiscardReasonHungUp{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	case "callDiscardReasonUpgradeToGroupCall":
		// Decoding callDiscardReasonUpgradeToGroupCall#4ac64b07.
		v := CallDiscardReasonUpgradeToGroupCall{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode CallDiscardReasonClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// CallDiscardReason boxes the CallDiscardReasonClass providing a helper.
type CallDiscardReasonBox struct {
	CallDiscardReason CallDiscardReasonClass
}

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

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

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

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