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

// RemoveFavoriteStickerRequest represents TL type `removeFavoriteSticker#44b88c70`.
type RemoveFavoriteStickerRequest struct {
	// Sticker file to delete from the list
	Sticker InputFileClass
}

// RemoveFavoriteStickerRequestTypeID is TL type id of RemoveFavoriteStickerRequest.
const RemoveFavoriteStickerRequestTypeID = 0x44b88c70

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

func (r *RemoveFavoriteStickerRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.Sticker == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *RemoveFavoriteStickerRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "removeFavoriteSticker",
		ID:   RemoveFavoriteStickerRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Sticker",
			SchemaName: "sticker",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *RemoveFavoriteStickerRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode removeFavoriteSticker#44b88c70 as nil")
	}
	b.PutID(RemoveFavoriteStickerRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *RemoveFavoriteStickerRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode removeFavoriteSticker#44b88c70 as nil")
	}
	if r.Sticker == nil {
		return fmt.Errorf("unable to encode removeFavoriteSticker#44b88c70: field sticker is nil")
	}
	if err := r.Sticker.Encode(b); err != nil {
		return fmt.Errorf("unable to encode removeFavoriteSticker#44b88c70: field sticker: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (r *RemoveFavoriteStickerRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode removeFavoriteSticker#44b88c70 to nil")
	}
	if err := b.ConsumeID(RemoveFavoriteStickerRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode removeFavoriteSticker#44b88c70: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *RemoveFavoriteStickerRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode removeFavoriteSticker#44b88c70 to nil")
	}
	{
		value, err := DecodeInputFile(b)
		if err != nil {
			return fmt.Errorf("unable to decode removeFavoriteSticker#44b88c70: field sticker: %w", err)
		}
		r.Sticker = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *RemoveFavoriteStickerRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode removeFavoriteSticker#44b88c70 as nil")
	}
	b.ObjStart()
	b.PutID("removeFavoriteSticker")
	b.Comma()
	b.FieldStart("sticker")
	if r.Sticker == nil {
		return fmt.Errorf("unable to encode removeFavoriteSticker#44b88c70: field sticker is nil")
	}
	if err := r.Sticker.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode removeFavoriteSticker#44b88c70: field sticker: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *RemoveFavoriteStickerRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode removeFavoriteSticker#44b88c70 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("removeFavoriteSticker"); err != nil {
				return fmt.Errorf("unable to decode removeFavoriteSticker#44b88c70: %w", err)
			}
		case "sticker":
			value, err := DecodeTDLibJSONInputFile(b)
			if err != nil {
				return fmt.Errorf("unable to decode removeFavoriteSticker#44b88c70: field sticker: %w", err)
			}
			r.Sticker = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetSticker returns value of Sticker field.
func (r *RemoveFavoriteStickerRequest) GetSticker() (value InputFileClass) {
	if r == nil {
		return
	}
	return r.Sticker
}

// RemoveFavoriteSticker invokes method removeFavoriteSticker#44b88c70 returning error if any.
func (c *Client) RemoveFavoriteSticker(ctx context.Context, sticker InputFileClass) error {
	var ok Ok

	request := &RemoveFavoriteStickerRequest{
		Sticker: sticker,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
