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

// GroupCallDataChannelMain represents TL type `groupCallDataChannelMain#fe15018d`.
type GroupCallDataChannelMain struct {
}

// GroupCallDataChannelMainTypeID is TL type id of GroupCallDataChannelMain.
const GroupCallDataChannelMainTypeID = 0xfe15018d

// construct implements constructor of GroupCallDataChannelClass.
func (g GroupCallDataChannelMain) construct() GroupCallDataChannelClass { return &g }

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

	_ GroupCallDataChannelClass = &GroupCallDataChannelMain{}
)

func (g *GroupCallDataChannelMain) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GroupCallDataChannelMain) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode groupCallDataChannelMain#fe15018d as nil")
	}
	b.PutID(GroupCallDataChannelMainTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GroupCallDataChannelMain) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode groupCallDataChannelMain#fe15018d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GroupCallDataChannelMain) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallDataChannelMain#fe15018d to nil")
	}
	if err := b.ConsumeID(GroupCallDataChannelMainTypeID); err != nil {
		return fmt.Errorf("unable to decode groupCallDataChannelMain#fe15018d: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GroupCallDataChannelMain) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallDataChannelMain#fe15018d to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GroupCallDataChannelMain) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallDataChannelMain#fe15018d to nil")
	}

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

// GroupCallDataChannelScreenSharing represents TL type `groupCallDataChannelScreenSharing#dc239031`.
type GroupCallDataChannelScreenSharing struct {
}

// GroupCallDataChannelScreenSharingTypeID is TL type id of GroupCallDataChannelScreenSharing.
const GroupCallDataChannelScreenSharingTypeID = 0xdc239031

// construct implements constructor of GroupCallDataChannelClass.
func (g GroupCallDataChannelScreenSharing) construct() GroupCallDataChannelClass { return &g }

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

	_ GroupCallDataChannelClass = &GroupCallDataChannelScreenSharing{}
)

func (g *GroupCallDataChannelScreenSharing) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GroupCallDataChannelScreenSharing) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode groupCallDataChannelScreenSharing#dc239031 as nil")
	}
	b.PutID(GroupCallDataChannelScreenSharingTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GroupCallDataChannelScreenSharing) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode groupCallDataChannelScreenSharing#dc239031 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GroupCallDataChannelScreenSharing) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallDataChannelScreenSharing#dc239031 to nil")
	}
	if err := b.ConsumeID(GroupCallDataChannelScreenSharingTypeID); err != nil {
		return fmt.Errorf("unable to decode groupCallDataChannelScreenSharing#dc239031: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GroupCallDataChannelScreenSharing) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallDataChannelScreenSharing#dc239031 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GroupCallDataChannelScreenSharing) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallDataChannelScreenSharing#dc239031 to nil")
	}

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

// GroupCallDataChannelClassName is schema name of GroupCallDataChannelClass.
const GroupCallDataChannelClassName = "GroupCallDataChannel"

// GroupCallDataChannelClass represents GroupCallDataChannel generic type.
//
// Example:
//
//	g, err := tdapi.DecodeGroupCallDataChannel(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.GroupCallDataChannelMain: // groupCallDataChannelMain#fe15018d
//	case *tdapi.GroupCallDataChannelScreenSharing: // groupCallDataChannelScreenSharing#dc239031
//	default: panic(v)
//	}
type GroupCallDataChannelClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() GroupCallDataChannelClass

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

// DecodeGroupCallDataChannel implements binary de-serialization for GroupCallDataChannelClass.
func DecodeGroupCallDataChannel(buf *bin.Buffer) (GroupCallDataChannelClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case GroupCallDataChannelMainTypeID:
		// Decoding groupCallDataChannelMain#fe15018d.
		v := GroupCallDataChannelMain{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GroupCallDataChannelClass: %w", err)
		}
		return &v, nil
	case GroupCallDataChannelScreenSharingTypeID:
		// Decoding groupCallDataChannelScreenSharing#dc239031.
		v := GroupCallDataChannelScreenSharing{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GroupCallDataChannelClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode GroupCallDataChannelClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONGroupCallDataChannel implements binary de-serialization for GroupCallDataChannelClass.
func DecodeTDLibJSONGroupCallDataChannel(buf tdjson.Decoder) (GroupCallDataChannelClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "groupCallDataChannelMain":
		// Decoding groupCallDataChannelMain#fe15018d.
		v := GroupCallDataChannelMain{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GroupCallDataChannelClass: %w", err)
		}
		return &v, nil
	case "groupCallDataChannelScreenSharing":
		// Decoding groupCallDataChannelScreenSharing#dc239031.
		v := GroupCallDataChannelScreenSharing{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GroupCallDataChannelClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode GroupCallDataChannelClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// GroupCallDataChannel boxes the GroupCallDataChannelClass providing a helper.
type GroupCallDataChannelBox struct {
	GroupCallDataChannel GroupCallDataChannelClass
}

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

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

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

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