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

// InviteLinkChatTypeBasicGroup represents TL type `inviteLinkChatTypeBasicGroup#4d43c5ee`.
type InviteLinkChatTypeBasicGroup struct {
}

// InviteLinkChatTypeBasicGroupTypeID is TL type id of InviteLinkChatTypeBasicGroup.
const InviteLinkChatTypeBasicGroupTypeID = 0x4d43c5ee

// construct implements constructor of InviteLinkChatTypeClass.
func (i InviteLinkChatTypeBasicGroup) construct() InviteLinkChatTypeClass { return &i }

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

	_ InviteLinkChatTypeClass = &InviteLinkChatTypeBasicGroup{}
)

func (i *InviteLinkChatTypeBasicGroup) Zero() bool {
	if i == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (i *InviteLinkChatTypeBasicGroup) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteLinkChatTypeBasicGroup#4d43c5ee as nil")
	}
	b.PutID(InviteLinkChatTypeBasicGroupTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InviteLinkChatTypeBasicGroup) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteLinkChatTypeBasicGroup#4d43c5ee as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (i *InviteLinkChatTypeBasicGroup) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeBasicGroup#4d43c5ee to nil")
	}
	if err := b.ConsumeID(InviteLinkChatTypeBasicGroupTypeID); err != nil {
		return fmt.Errorf("unable to decode inviteLinkChatTypeBasicGroup#4d43c5ee: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InviteLinkChatTypeBasicGroup) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeBasicGroup#4d43c5ee to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (i *InviteLinkChatTypeBasicGroup) EncodeTDLibJSON(b tdjson.Encoder) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteLinkChatTypeBasicGroup#4d43c5ee as nil")
	}
	b.ObjStart()
	b.PutID("inviteLinkChatTypeBasicGroup")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (i *InviteLinkChatTypeBasicGroup) DecodeTDLibJSON(b tdjson.Decoder) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeBasicGroup#4d43c5ee to nil")
	}

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

// InviteLinkChatTypeSupergroup represents TL type `inviteLinkChatTypeSupergroup#3de86758`.
type InviteLinkChatTypeSupergroup struct {
}

// InviteLinkChatTypeSupergroupTypeID is TL type id of InviteLinkChatTypeSupergroup.
const InviteLinkChatTypeSupergroupTypeID = 0x3de86758

// construct implements constructor of InviteLinkChatTypeClass.
func (i InviteLinkChatTypeSupergroup) construct() InviteLinkChatTypeClass { return &i }

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

	_ InviteLinkChatTypeClass = &InviteLinkChatTypeSupergroup{}
)

func (i *InviteLinkChatTypeSupergroup) Zero() bool {
	if i == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (i *InviteLinkChatTypeSupergroup) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteLinkChatTypeSupergroup#3de86758 as nil")
	}
	b.PutID(InviteLinkChatTypeSupergroupTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InviteLinkChatTypeSupergroup) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteLinkChatTypeSupergroup#3de86758 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (i *InviteLinkChatTypeSupergroup) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeSupergroup#3de86758 to nil")
	}
	if err := b.ConsumeID(InviteLinkChatTypeSupergroupTypeID); err != nil {
		return fmt.Errorf("unable to decode inviteLinkChatTypeSupergroup#3de86758: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InviteLinkChatTypeSupergroup) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeSupergroup#3de86758 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (i *InviteLinkChatTypeSupergroup) DecodeTDLibJSON(b tdjson.Decoder) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeSupergroup#3de86758 to nil")
	}

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

// InviteLinkChatTypeChannel represents TL type `inviteLinkChatTypeChannel#3012ef0b`.
type InviteLinkChatTypeChannel struct {
}

// InviteLinkChatTypeChannelTypeID is TL type id of InviteLinkChatTypeChannel.
const InviteLinkChatTypeChannelTypeID = 0x3012ef0b

// construct implements constructor of InviteLinkChatTypeClass.
func (i InviteLinkChatTypeChannel) construct() InviteLinkChatTypeClass { return &i }

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

	_ InviteLinkChatTypeClass = &InviteLinkChatTypeChannel{}
)

func (i *InviteLinkChatTypeChannel) Zero() bool {
	if i == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (i *InviteLinkChatTypeChannel) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteLinkChatTypeChannel#3012ef0b as nil")
	}
	b.PutID(InviteLinkChatTypeChannelTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InviteLinkChatTypeChannel) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteLinkChatTypeChannel#3012ef0b as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (i *InviteLinkChatTypeChannel) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeChannel#3012ef0b to nil")
	}
	if err := b.ConsumeID(InviteLinkChatTypeChannelTypeID); err != nil {
		return fmt.Errorf("unable to decode inviteLinkChatTypeChannel#3012ef0b: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InviteLinkChatTypeChannel) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeChannel#3012ef0b to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (i *InviteLinkChatTypeChannel) EncodeTDLibJSON(b tdjson.Encoder) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteLinkChatTypeChannel#3012ef0b as nil")
	}
	b.ObjStart()
	b.PutID("inviteLinkChatTypeChannel")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (i *InviteLinkChatTypeChannel) DecodeTDLibJSON(b tdjson.Decoder) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteLinkChatTypeChannel#3012ef0b to nil")
	}

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

// InviteLinkChatTypeClassName is schema name of InviteLinkChatTypeClass.
const InviteLinkChatTypeClassName = "InviteLinkChatType"

// InviteLinkChatTypeClass represents InviteLinkChatType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeInviteLinkChatType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.InviteLinkChatTypeBasicGroup: // inviteLinkChatTypeBasicGroup#4d43c5ee
//	case *tdapi.InviteLinkChatTypeSupergroup: // inviteLinkChatTypeSupergroup#3de86758
//	case *tdapi.InviteLinkChatTypeChannel: // inviteLinkChatTypeChannel#3012ef0b
//	default: panic(v)
//	}
type InviteLinkChatTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() InviteLinkChatTypeClass

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

// DecodeInviteLinkChatType implements binary de-serialization for InviteLinkChatTypeClass.
func DecodeInviteLinkChatType(buf *bin.Buffer) (InviteLinkChatTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case InviteLinkChatTypeBasicGroupTypeID:
		// Decoding inviteLinkChatTypeBasicGroup#4d43c5ee.
		v := InviteLinkChatTypeBasicGroup{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InviteLinkChatTypeClass: %w", err)
		}
		return &v, nil
	case InviteLinkChatTypeSupergroupTypeID:
		// Decoding inviteLinkChatTypeSupergroup#3de86758.
		v := InviteLinkChatTypeSupergroup{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InviteLinkChatTypeClass: %w", err)
		}
		return &v, nil
	case InviteLinkChatTypeChannelTypeID:
		// Decoding inviteLinkChatTypeChannel#3012ef0b.
		v := InviteLinkChatTypeChannel{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InviteLinkChatTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode InviteLinkChatTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONInviteLinkChatType implements binary de-serialization for InviteLinkChatTypeClass.
func DecodeTDLibJSONInviteLinkChatType(buf tdjson.Decoder) (InviteLinkChatTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "inviteLinkChatTypeBasicGroup":
		// Decoding inviteLinkChatTypeBasicGroup#4d43c5ee.
		v := InviteLinkChatTypeBasicGroup{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InviteLinkChatTypeClass: %w", err)
		}
		return &v, nil
	case "inviteLinkChatTypeSupergroup":
		// Decoding inviteLinkChatTypeSupergroup#3de86758.
		v := InviteLinkChatTypeSupergroup{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InviteLinkChatTypeClass: %w", err)
		}
		return &v, nil
	case "inviteLinkChatTypeChannel":
		// Decoding inviteLinkChatTypeChannel#3012ef0b.
		v := InviteLinkChatTypeChannel{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InviteLinkChatTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode InviteLinkChatTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// InviteLinkChatType boxes the InviteLinkChatTypeClass providing a helper.
type InviteLinkChatTypeBox struct {
	InviteLinkChatType InviteLinkChatTypeClass
}

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

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

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

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