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

// ClearSearchedForTagsRequest represents TL type `clearSearchedForTags#1e84c356`.
type ClearSearchedForTagsRequest struct {
	// Pass true to clear the list of recently searched for cashtags; otherwise, the list of
	// recently searched for hashtags will be cleared
	ClearCashtags bool
}

// ClearSearchedForTagsRequestTypeID is TL type id of ClearSearchedForTagsRequest.
const ClearSearchedForTagsRequestTypeID = 0x1e84c356

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *ClearSearchedForTagsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "clearSearchedForTags",
		ID:   ClearSearchedForTagsRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ClearCashtags",
			SchemaName: "clear_cashtags",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ClearSearchedForTagsRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clearSearchedForTags#1e84c356 as nil")
	}
	b.PutID(ClearSearchedForTagsRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ClearSearchedForTagsRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clearSearchedForTags#1e84c356 as nil")
	}
	b.PutBool(c.ClearCashtags)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (c *ClearSearchedForTagsRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode clearSearchedForTags#1e84c356 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode clearSearchedForTags#1e84c356: field clear_cashtags: %w", err)
		}
		c.ClearCashtags = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ClearSearchedForTagsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode clearSearchedForTags#1e84c356 as nil")
	}
	b.ObjStart()
	b.PutID("clearSearchedForTags")
	b.Comma()
	b.FieldStart("clear_cashtags")
	b.PutBool(c.ClearCashtags)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetClearCashtags returns value of ClearCashtags field.
func (c *ClearSearchedForTagsRequest) GetClearCashtags() (value bool) {
	if c == nil {
		return
	}
	return c.ClearCashtags
}

// ClearSearchedForTags invokes method clearSearchedForTags#1e84c356 returning error if any.
func (c *Client) ClearSearchedForTags(ctx context.Context, clearcashtags bool) error {
	var ok Ok

	request := &ClearSearchedForTagsRequest{
		ClearCashtags: clearcashtags,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
