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

// RemoveSearchedForTagRequest represents TL type `removeSearchedForTag#35216bca`.
type RemoveSearchedForTagRequest struct {
	// Hashtag or cashtag to delete
	Tag string
}

// RemoveSearchedForTagRequestTypeID is TL type id of RemoveSearchedForTagRequest.
const RemoveSearchedForTagRequestTypeID = 0x35216bca

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

func (r *RemoveSearchedForTagRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.Tag == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *RemoveSearchedForTagRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "removeSearchedForTag",
		ID:   RemoveSearchedForTagRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Tag",
			SchemaName: "tag",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *RemoveSearchedForTagRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode removeSearchedForTag#35216bca as nil")
	}
	b.PutID(RemoveSearchedForTagRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *RemoveSearchedForTagRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode removeSearchedForTag#35216bca as nil")
	}
	b.PutString(r.Tag)
	return nil
}

// Decode implements bin.Decoder.
func (r *RemoveSearchedForTagRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode removeSearchedForTag#35216bca to nil")
	}
	if err := b.ConsumeID(RemoveSearchedForTagRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode removeSearchedForTag#35216bca: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *RemoveSearchedForTagRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode removeSearchedForTag#35216bca to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode removeSearchedForTag#35216bca: field tag: %w", err)
		}
		r.Tag = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *RemoveSearchedForTagRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode removeSearchedForTag#35216bca as nil")
	}
	b.ObjStart()
	b.PutID("removeSearchedForTag")
	b.Comma()
	b.FieldStart("tag")
	b.PutString(r.Tag)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *RemoveSearchedForTagRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode removeSearchedForTag#35216bca to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("removeSearchedForTag"); err != nil {
				return fmt.Errorf("unable to decode removeSearchedForTag#35216bca: %w", err)
			}
		case "tag":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode removeSearchedForTag#35216bca: field tag: %w", err)
			}
			r.Tag = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetTag returns value of Tag field.
func (r *RemoveSearchedForTagRequest) GetTag() (value string) {
	if r == nil {
		return
	}
	return r.Tag
}

// RemoveSearchedForTag invokes method removeSearchedForTag#35216bca returning error if any.
func (c *Client) RemoveSearchedForTag(ctx context.Context, tag string) error {
	var ok Ok

	request := &RemoveSearchedForTagRequest{
		Tag: tag,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
