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

// ClearRecentStickersRequest represents TL type `clearRecentStickers#ecda39c4`.
type ClearRecentStickersRequest struct {
	// Pass true to clear the list of stickers recently attached to photo or video files;
	// pass false to clear the list of recently sent stickers
	IsAttached bool
}

// ClearRecentStickersRequestTypeID is TL type id of ClearRecentStickersRequest.
const ClearRecentStickersRequestTypeID = 0xecda39c4

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

func (c *ClearRecentStickersRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.IsAttached == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *ClearRecentStickersRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "clearRecentStickers",
		ID:   ClearRecentStickersRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "IsAttached",
			SchemaName: "is_attached",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ClearRecentStickersRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clearRecentStickers#ecda39c4 as nil")
	}
	b.PutID(ClearRecentStickersRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ClearRecentStickersRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clearRecentStickers#ecda39c4 as nil")
	}
	b.PutBool(c.IsAttached)
	return nil
}

// Decode implements bin.Decoder.
func (c *ClearRecentStickersRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode clearRecentStickers#ecda39c4 to nil")
	}
	if err := b.ConsumeID(ClearRecentStickersRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode clearRecentStickers#ecda39c4: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *ClearRecentStickersRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode clearRecentStickers#ecda39c4 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode clearRecentStickers#ecda39c4: field is_attached: %w", err)
		}
		c.IsAttached = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ClearRecentStickersRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode clearRecentStickers#ecda39c4 as nil")
	}
	b.ObjStart()
	b.PutID("clearRecentStickers")
	b.Comma()
	b.FieldStart("is_attached")
	b.PutBool(c.IsAttached)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *ClearRecentStickersRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode clearRecentStickers#ecda39c4 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("clearRecentStickers"); err != nil {
				return fmt.Errorf("unable to decode clearRecentStickers#ecda39c4: %w", err)
			}
		case "is_attached":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode clearRecentStickers#ecda39c4: field is_attached: %w", err)
			}
			c.IsAttached = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetIsAttached returns value of IsAttached field.
func (c *ClearRecentStickersRequest) GetIsAttached() (value bool) {
	if c == nil {
		return
	}
	return c.IsAttached
}

// ClearRecentStickers invokes method clearRecentStickers#ecda39c4 returning error if any.
func (c *Client) ClearRecentStickers(ctx context.Context, isattached bool) error {
	var ok Ok

	request := &ClearRecentStickersRequest{
		IsAttached: isattached,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
