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

// AccountSavedMusicIDsNotModified represents TL type `account.savedMusicIdsNotModified#4fc81d6e`.
// The list of IDs of songs (document¹.ids) currently pinned on our profile hasn't
// changed.
//
// Links:
//  1. https://core.telegram.org/constructor/document
//
// See https://core.telegram.org/constructor/account.savedMusicIdsNotModified for reference.
type AccountSavedMusicIDsNotModified struct {
}

// AccountSavedMusicIDsNotModifiedTypeID is TL type id of AccountSavedMusicIDsNotModified.
const AccountSavedMusicIDsNotModifiedTypeID = 0x4fc81d6e

// construct implements constructor of AccountSavedMusicIDsClass.
func (s AccountSavedMusicIDsNotModified) construct() AccountSavedMusicIDsClass { return &s }

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

	_ AccountSavedMusicIDsClass = &AccountSavedMusicIDsNotModified{}
)

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

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*AccountSavedMusicIDsNotModified) TypeName() string {
	return "account.savedMusicIdsNotModified"
}

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

// Encode implements bin.Encoder.
func (s *AccountSavedMusicIDsNotModified) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode account.savedMusicIdsNotModified#4fc81d6e as nil")
	}
	b.PutID(AccountSavedMusicIDsNotModifiedTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AccountSavedMusicIDsNotModified) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode account.savedMusicIdsNotModified#4fc81d6e as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *AccountSavedMusicIDsNotModified) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode account.savedMusicIdsNotModified#4fc81d6e to nil")
	}
	if err := b.ConsumeID(AccountSavedMusicIDsNotModifiedTypeID); err != nil {
		return fmt.Errorf("unable to decode account.savedMusicIdsNotModified#4fc81d6e: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AccountSavedMusicIDsNotModified) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode account.savedMusicIdsNotModified#4fc81d6e to nil")
	}
	return nil
}

// AccountSavedMusicIDs represents TL type `account.savedMusicIds#998d6636`.
// List of IDs of songs (document¹.ids) currently pinned on our profile, see here »²
// for more info.
//
// Links:
//  1. https://core.telegram.org/constructor/document
//  2. https://core.telegram.org/api/profile#music
//
// See https://core.telegram.org/constructor/account.savedMusicIds for reference.
type AccountSavedMusicIDs struct {
	// Full list of document¹.ids
	//
	// Links:
	//  1) https://core.telegram.org/constructor/document
	IDs []int64
}

// AccountSavedMusicIDsTypeID is TL type id of AccountSavedMusicIDs.
const AccountSavedMusicIDsTypeID = 0x998d6636

// construct implements constructor of AccountSavedMusicIDsClass.
func (s AccountSavedMusicIDs) construct() AccountSavedMusicIDsClass { return &s }

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

	_ AccountSavedMusicIDsClass = &AccountSavedMusicIDs{}
)

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

	return true
}

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

// FillFrom fills AccountSavedMusicIDs from given interface.
func (s *AccountSavedMusicIDs) FillFrom(from interface {
	GetIDs() (value []int64)
}) {
	s.IDs = from.GetIDs()
}

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

// TypeName returns name of type in TL schema.
func (*AccountSavedMusicIDs) TypeName() string {
	return "account.savedMusicIds"
}

// TypeInfo returns info about TL type.
func (s *AccountSavedMusicIDs) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.savedMusicIds",
		ID:   AccountSavedMusicIDsTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "IDs",
			SchemaName: "ids",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *AccountSavedMusicIDs) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode account.savedMusicIds#998d6636 as nil")
	}
	b.PutID(AccountSavedMusicIDsTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AccountSavedMusicIDs) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode account.savedMusicIds#998d6636 as nil")
	}
	b.PutVectorHeader(len(s.IDs))
	for _, v := range s.IDs {
		b.PutLong(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *AccountSavedMusicIDs) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode account.savedMusicIds#998d6636 to nil")
	}
	if err := b.ConsumeID(AccountSavedMusicIDsTypeID); err != nil {
		return fmt.Errorf("unable to decode account.savedMusicIds#998d6636: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AccountSavedMusicIDs) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode account.savedMusicIds#998d6636 to nil")
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode account.savedMusicIds#998d6636: field ids: %w", err)
		}

		if headerLen > 0 {
			s.IDs = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode account.savedMusicIds#998d6636: field ids: %w", err)
			}
			s.IDs = append(s.IDs, value)
		}
	}
	return nil
}

// GetIDs returns value of IDs field.
func (s *AccountSavedMusicIDs) GetIDs() (value []int64) {
	if s == nil {
		return
	}
	return s.IDs
}

// AccountSavedMusicIDsClassName is schema name of AccountSavedMusicIDsClass.
const AccountSavedMusicIDsClassName = "account.SavedMusicIds"

// AccountSavedMusicIDsClass represents account.SavedMusicIds generic type.
//
// See https://core.telegram.org/type/account.SavedMusicIds for reference.
//
// Example:
//
//	g, err := tg.DecodeAccountSavedMusicIDs(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.AccountSavedMusicIDsNotModified: // account.savedMusicIdsNotModified#4fc81d6e
//	case *tg.AccountSavedMusicIDs: // account.savedMusicIds#998d6636
//	default: panic(v)
//	}
type AccountSavedMusicIDsClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() AccountSavedMusicIDsClass

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

	// AsModified tries to map AccountSavedMusicIDsClass to AccountSavedMusicIDs.
	AsModified() (*AccountSavedMusicIDs, bool)
}

// AsModified tries to map AccountSavedMusicIDsNotModified to AccountSavedMusicIDs.
func (s *AccountSavedMusicIDsNotModified) AsModified() (*AccountSavedMusicIDs, bool) {
	return nil, false
}

// AsModified tries to map AccountSavedMusicIDs to AccountSavedMusicIDs.
func (s *AccountSavedMusicIDs) AsModified() (*AccountSavedMusicIDs, bool) {
	return s, true
}

// DecodeAccountSavedMusicIDs implements binary de-serialization for AccountSavedMusicIDsClass.
func DecodeAccountSavedMusicIDs(buf *bin.Buffer) (AccountSavedMusicIDsClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case AccountSavedMusicIDsNotModifiedTypeID:
		// Decoding account.savedMusicIdsNotModified#4fc81d6e.
		v := AccountSavedMusicIDsNotModified{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AccountSavedMusicIDsClass: %w", err)
		}
		return &v, nil
	case AccountSavedMusicIDsTypeID:
		// Decoding account.savedMusicIds#998d6636.
		v := AccountSavedMusicIDs{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AccountSavedMusicIDsClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode AccountSavedMusicIDsClass: %w", bin.NewUnexpectedID(id))
	}
}

// AccountSavedMusicIDs boxes the AccountSavedMusicIDsClass providing a helper.
type AccountSavedMusicIDsBox struct {
	SavedMusicIds AccountSavedMusicIDsClass
}

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

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