// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// MessagesStickerSetInstallResultSuccess represents TL type `messages.stickerSetInstallResultSuccess#38641628`.
// The stickerset was installed successfully
//
// See https://core.telegram.org/constructor/messages.stickerSetInstallResultSuccess for reference.
type MessagesStickerSetInstallResultSuccess struct {
}

// MessagesStickerSetInstallResultSuccessTypeID is TL type id of MessagesStickerSetInstallResultSuccess.
const MessagesStickerSetInstallResultSuccessTypeID = 0x38641628

// construct implements constructor of MessagesStickerSetInstallResultClass.
func (s MessagesStickerSetInstallResultSuccess) construct() MessagesStickerSetInstallResultClass {
	return &s
}

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

	_ MessagesStickerSetInstallResultClass = &MessagesStickerSetInstallResultSuccess{}
)

func (s *MessagesStickerSetInstallResultSuccess) Zero() bool {
	if s == nil {
		return true
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*MessagesStickerSetInstallResultSuccess) TypeName() string {
	return "messages.stickerSetInstallResultSuccess"
}

// TypeInfo returns info about TL type.
func (s *MessagesStickerSetInstallResultSuccess) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.stickerSetInstallResultSuccess",
		ID:   MessagesStickerSetInstallResultSuccessTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (s *MessagesStickerSetInstallResultSuccess) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.stickerSetInstallResultSuccess#38641628 as nil")
	}
	b.PutID(MessagesStickerSetInstallResultSuccessTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *MessagesStickerSetInstallResultSuccess) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.stickerSetInstallResultSuccess#38641628 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *MessagesStickerSetInstallResultSuccess) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.stickerSetInstallResultSuccess#38641628 to nil")
	}
	if err := b.ConsumeID(MessagesStickerSetInstallResultSuccessTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.stickerSetInstallResultSuccess#38641628: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *MessagesStickerSetInstallResultSuccess) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.stickerSetInstallResultSuccess#38641628 to nil")
	}
	return nil
}

// MessagesStickerSetInstallResultArchive represents TL type `messages.stickerSetInstallResultArchive#35e410a8`.
// The stickerset was installed, but since there are too many stickersets some were
// archived
//
// See https://core.telegram.org/constructor/messages.stickerSetInstallResultArchive for reference.
type MessagesStickerSetInstallResultArchive struct {
	// Archived stickersets
	Sets []StickerSetCoveredClass
}

// MessagesStickerSetInstallResultArchiveTypeID is TL type id of MessagesStickerSetInstallResultArchive.
const MessagesStickerSetInstallResultArchiveTypeID = 0x35e410a8

// construct implements constructor of MessagesStickerSetInstallResultClass.
func (s MessagesStickerSetInstallResultArchive) construct() MessagesStickerSetInstallResultClass {
	return &s
}

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

	_ MessagesStickerSetInstallResultClass = &MessagesStickerSetInstallResultArchive{}
)

func (s *MessagesStickerSetInstallResultArchive) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Sets == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesStickerSetInstallResultArchive from given interface.
func (s *MessagesStickerSetInstallResultArchive) FillFrom(from interface {
	GetSets() (value []StickerSetCoveredClass)
}) {
	s.Sets = from.GetSets()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesStickerSetInstallResultArchive) TypeName() string {
	return "messages.stickerSetInstallResultArchive"
}

// TypeInfo returns info about TL type.
func (s *MessagesStickerSetInstallResultArchive) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.stickerSetInstallResultArchive",
		ID:   MessagesStickerSetInstallResultArchiveTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Sets",
			SchemaName: "sets",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *MessagesStickerSetInstallResultArchive) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.stickerSetInstallResultArchive#35e410a8 as nil")
	}
	b.PutID(MessagesStickerSetInstallResultArchiveTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *MessagesStickerSetInstallResultArchive) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.stickerSetInstallResultArchive#35e410a8 as nil")
	}
	b.PutVectorHeader(len(s.Sets))
	for idx, v := range s.Sets {
		if v == nil {
			return fmt.Errorf("unable to encode messages.stickerSetInstallResultArchive#35e410a8: field sets element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.stickerSetInstallResultArchive#35e410a8: field sets element with index %d: %w", idx, err)
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *MessagesStickerSetInstallResultArchive) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.stickerSetInstallResultArchive#35e410a8 to nil")
	}
	if err := b.ConsumeID(MessagesStickerSetInstallResultArchiveTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.stickerSetInstallResultArchive#35e410a8: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *MessagesStickerSetInstallResultArchive) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.stickerSetInstallResultArchive#35e410a8 to nil")
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.stickerSetInstallResultArchive#35e410a8: field sets: %w", err)
		}

		if headerLen > 0 {
			s.Sets = make([]StickerSetCoveredClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeStickerSetCovered(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.stickerSetInstallResultArchive#35e410a8: field sets: %w", err)
			}
			s.Sets = append(s.Sets, value)
		}
	}
	return nil
}

// GetSets returns value of Sets field.
func (s *MessagesStickerSetInstallResultArchive) GetSets() (value []StickerSetCoveredClass) {
	if s == nil {
		return
	}
	return s.Sets
}

// MapSets returns field Sets wrapped in StickerSetCoveredClassArray helper.
func (s *MessagesStickerSetInstallResultArchive) MapSets() (value StickerSetCoveredClassArray) {
	return StickerSetCoveredClassArray(s.Sets)
}

// MessagesStickerSetInstallResultClassName is schema name of MessagesStickerSetInstallResultClass.
const MessagesStickerSetInstallResultClassName = "messages.StickerSetInstallResult"

// MessagesStickerSetInstallResultClass represents messages.StickerSetInstallResult generic type.
//
// See https://core.telegram.org/type/messages.StickerSetInstallResult for reference.
//
// Example:
//
//	g, err := tg.DecodeMessagesStickerSetInstallResult(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.MessagesStickerSetInstallResultSuccess: // messages.stickerSetInstallResultSuccess#38641628
//	case *tg.MessagesStickerSetInstallResultArchive: // messages.stickerSetInstallResultArchive#35e410a8
//	default: panic(v)
//	}
type MessagesStickerSetInstallResultClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessagesStickerSetInstallResultClass

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

// DecodeMessagesStickerSetInstallResult implements binary de-serialization for MessagesStickerSetInstallResultClass.
func DecodeMessagesStickerSetInstallResult(buf *bin.Buffer) (MessagesStickerSetInstallResultClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case MessagesStickerSetInstallResultSuccessTypeID:
		// Decoding messages.stickerSetInstallResultSuccess#38641628.
		v := MessagesStickerSetInstallResultSuccess{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessagesStickerSetInstallResultClass: %w", err)
		}
		return &v, nil
	case MessagesStickerSetInstallResultArchiveTypeID:
		// Decoding messages.stickerSetInstallResultArchive#35e410a8.
		v := MessagesStickerSetInstallResultArchive{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessagesStickerSetInstallResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode MessagesStickerSetInstallResultClass: %w", bin.NewUnexpectedID(id))
	}
}

// MessagesStickerSetInstallResult boxes the MessagesStickerSetInstallResultClass providing a helper.
type MessagesStickerSetInstallResultBox struct {
	StickerSetInstallResult MessagesStickerSetInstallResultClass
}

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

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