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

// DeleteStickerSetRequest represents TL type `deleteStickerSet#5e0a7bad`.
type DeleteStickerSetRequest struct {
	// Sticker set name. The sticker set must be owned by the current user
	Name string
}

// DeleteStickerSetRequestTypeID is TL type id of DeleteStickerSetRequest.
const DeleteStickerSetRequestTypeID = 0x5e0a7bad

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

func (d *DeleteStickerSetRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.Name == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (d *DeleteStickerSetRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "deleteStickerSet",
		ID:   DeleteStickerSetRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Name",
			SchemaName: "name",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *DeleteStickerSetRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteStickerSet#5e0a7bad as nil")
	}
	b.PutID(DeleteStickerSetRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeleteStickerSetRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteStickerSet#5e0a7bad as nil")
	}
	b.PutString(d.Name)
	return nil
}

// Decode implements bin.Decoder.
func (d *DeleteStickerSetRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteStickerSet#5e0a7bad to nil")
	}
	if err := b.ConsumeID(DeleteStickerSetRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode deleteStickerSet#5e0a7bad: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *DeleteStickerSetRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteStickerSet#5e0a7bad to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode deleteStickerSet#5e0a7bad: field name: %w", err)
		}
		d.Name = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeleteStickerSetRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteStickerSet#5e0a7bad as nil")
	}
	b.ObjStart()
	b.PutID("deleteStickerSet")
	b.Comma()
	b.FieldStart("name")
	b.PutString(d.Name)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (d *DeleteStickerSetRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteStickerSet#5e0a7bad to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("deleteStickerSet"); err != nil {
				return fmt.Errorf("unable to decode deleteStickerSet#5e0a7bad: %w", err)
			}
		case "name":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode deleteStickerSet#5e0a7bad: field name: %w", err)
			}
			d.Name = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetName returns value of Name field.
func (d *DeleteStickerSetRequest) GetName() (value string) {
	if d == nil {
		return
	}
	return d.Name
}

// DeleteStickerSet invokes method deleteStickerSet#5e0a7bad returning error if any.
func (c *Client) DeleteStickerSet(ctx context.Context, name string) error {
	var ok Ok

	request := &DeleteStickerSetRequest{
		Name: name,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
