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

// AccountGetSavedMusicIDsRequest represents TL type `account.getSavedMusicIds#e09d5faf`.
// Fetch the full list of only the IDs of songs currently added to the profile, see here
// »¹ for more info.
//
// Links:
//  1. https://core.telegram.org/api/profile#music
//
// See https://core.telegram.org/method/account.getSavedMusicIds for reference.
type AccountGetSavedMusicIDsRequest struct {
	// Hash generated »¹ from the previously returned list of IDs.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int64
}

// AccountGetSavedMusicIDsRequestTypeID is TL type id of AccountGetSavedMusicIDsRequest.
const AccountGetSavedMusicIDsRequestTypeID = 0xe09d5faf

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

func (g *AccountGetSavedMusicIDsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AccountGetSavedMusicIDsRequest from given interface.
func (g *AccountGetSavedMusicIDsRequest) FillFrom(from interface {
	GetHash() (value int64)
}) {
	g.Hash = from.GetHash()
}

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

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

// TypeInfo returns info about TL type.
func (g *AccountGetSavedMusicIDsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.getSavedMusicIds",
		ID:   AccountGetSavedMusicIDsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *AccountGetSavedMusicIDsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode account.getSavedMusicIds#e09d5faf as nil")
	}
	b.PutID(AccountGetSavedMusicIDsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *AccountGetSavedMusicIDsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode account.getSavedMusicIds#e09d5faf as nil")
	}
	b.PutLong(g.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *AccountGetSavedMusicIDsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode account.getSavedMusicIds#e09d5faf to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode account.getSavedMusicIds#e09d5faf: field hash: %w", err)
		}
		g.Hash = value
	}
	return nil
}

// GetHash returns value of Hash field.
func (g *AccountGetSavedMusicIDsRequest) GetHash() (value int64) {
	if g == nil {
		return
	}
	return g.Hash
}

// AccountGetSavedMusicIDs invokes method account.getSavedMusicIds#e09d5faf returning error if any.
// Fetch the full list of only the IDs of songs currently added to the profile, see here
// »¹ for more info.
//
// Links:
//  1. https://core.telegram.org/api/profile#music
//
// See https://core.telegram.org/method/account.getSavedMusicIds for reference.
func (c *Client) AccountGetSavedMusicIDs(ctx context.Context, hash int64) (AccountSavedMusicIDsClass, error) {
	var result AccountSavedMusicIDsBox

	request := &AccountGetSavedMusicIDsRequest{
		Hash: hash,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return result.SavedMusicIds, nil
}
