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

// StickersRenameStickerSetRequest represents TL type `stickers.renameStickerSet#124b1c00`.
// Renames a stickerset.
//
// See https://core.telegram.org/method/stickers.renameStickerSet for reference.
type StickersRenameStickerSetRequest struct {
	// Stickerset to rename
	Stickerset InputStickerSetClass
	// New stickerset title
	Title string
}

// StickersRenameStickerSetRequestTypeID is TL type id of StickersRenameStickerSetRequest.
const StickersRenameStickerSetRequestTypeID = 0x124b1c00

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

func (r *StickersRenameStickerSetRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.Stickerset == nil) {
		return false
	}
	if !(r.Title == "") {
		return false
	}

	return true
}

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

// FillFrom fills StickersRenameStickerSetRequest from given interface.
func (r *StickersRenameStickerSetRequest) FillFrom(from interface {
	GetStickerset() (value InputStickerSetClass)
	GetTitle() (value string)
}) {
	r.Stickerset = from.GetStickerset()
	r.Title = from.GetTitle()
}

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

// TypeName returns name of type in TL schema.
func (*StickersRenameStickerSetRequest) TypeName() string {
	return "stickers.renameStickerSet"
}

// TypeInfo returns info about TL type.
func (r *StickersRenameStickerSetRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "stickers.renameStickerSet",
		ID:   StickersRenameStickerSetRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Stickerset",
			SchemaName: "stickerset",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *StickersRenameStickerSetRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode stickers.renameStickerSet#124b1c00 as nil")
	}
	b.PutID(StickersRenameStickerSetRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *StickersRenameStickerSetRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode stickers.renameStickerSet#124b1c00 as nil")
	}
	if r.Stickerset == nil {
		return fmt.Errorf("unable to encode stickers.renameStickerSet#124b1c00: field stickerset is nil")
	}
	if err := r.Stickerset.Encode(b); err != nil {
		return fmt.Errorf("unable to encode stickers.renameStickerSet#124b1c00: field stickerset: %w", err)
	}
	b.PutString(r.Title)
	return nil
}

// Decode implements bin.Decoder.
func (r *StickersRenameStickerSetRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode stickers.renameStickerSet#124b1c00 to nil")
	}
	if err := b.ConsumeID(StickersRenameStickerSetRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode stickers.renameStickerSet#124b1c00: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *StickersRenameStickerSetRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode stickers.renameStickerSet#124b1c00 to nil")
	}
	{
		value, err := DecodeInputStickerSet(b)
		if err != nil {
			return fmt.Errorf("unable to decode stickers.renameStickerSet#124b1c00: field stickerset: %w", err)
		}
		r.Stickerset = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode stickers.renameStickerSet#124b1c00: field title: %w", err)
		}
		r.Title = value
	}
	return nil
}

// GetStickerset returns value of Stickerset field.
func (r *StickersRenameStickerSetRequest) GetStickerset() (value InputStickerSetClass) {
	if r == nil {
		return
	}
	return r.Stickerset
}

// GetTitle returns value of Title field.
func (r *StickersRenameStickerSetRequest) GetTitle() (value string) {
	if r == nil {
		return
	}
	return r.Title
}

// StickersRenameStickerSet invokes method stickers.renameStickerSet#124b1c00 returning error if any.
// Renames a stickerset.
//
// Possible errors:
//
//	400 STICKERSET_INVALID: The provided sticker set is invalid.
//
// See https://core.telegram.org/method/stickers.renameStickerSet for reference.
func (c *Client) StickersRenameStickerSet(ctx context.Context, request *StickersRenameStickerSetRequest) (MessagesStickerSetClass, error) {
	var result MessagesStickerSetBox

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