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

// HideSuggestedActionRequest represents TL type `hideSuggestedAction#a2ef2b7f`.
type HideSuggestedActionRequest struct {
	// Suggested action to hide
	Action SuggestedActionClass
}

// HideSuggestedActionRequestTypeID is TL type id of HideSuggestedActionRequest.
const HideSuggestedActionRequestTypeID = 0xa2ef2b7f

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

func (h *HideSuggestedActionRequest) Zero() bool {
	if h == nil {
		return true
	}
	if !(h.Action == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (h *HideSuggestedActionRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "hideSuggestedAction",
		ID:   HideSuggestedActionRequestTypeID,
	}
	if h == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Action",
			SchemaName: "action",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (h *HideSuggestedActionRequest) Encode(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't encode hideSuggestedAction#a2ef2b7f as nil")
	}
	b.PutID(HideSuggestedActionRequestTypeID)
	return h.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (h *HideSuggestedActionRequest) EncodeBare(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't encode hideSuggestedAction#a2ef2b7f as nil")
	}
	if h.Action == nil {
		return fmt.Errorf("unable to encode hideSuggestedAction#a2ef2b7f: field action is nil")
	}
	if err := h.Action.Encode(b); err != nil {
		return fmt.Errorf("unable to encode hideSuggestedAction#a2ef2b7f: field action: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (h *HideSuggestedActionRequest) Decode(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't decode hideSuggestedAction#a2ef2b7f to nil")
	}
	if err := b.ConsumeID(HideSuggestedActionRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode hideSuggestedAction#a2ef2b7f: %w", err)
	}
	return h.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (h *HideSuggestedActionRequest) DecodeBare(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't decode hideSuggestedAction#a2ef2b7f to nil")
	}
	{
		value, err := DecodeSuggestedAction(b)
		if err != nil {
			return fmt.Errorf("unable to decode hideSuggestedAction#a2ef2b7f: field action: %w", err)
		}
		h.Action = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (h *HideSuggestedActionRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if h == nil {
		return fmt.Errorf("can't encode hideSuggestedAction#a2ef2b7f as nil")
	}
	b.ObjStart()
	b.PutID("hideSuggestedAction")
	b.Comma()
	b.FieldStart("action")
	if h.Action == nil {
		return fmt.Errorf("unable to encode hideSuggestedAction#a2ef2b7f: field action is nil")
	}
	if err := h.Action.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode hideSuggestedAction#a2ef2b7f: field action: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (h *HideSuggestedActionRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if h == nil {
		return fmt.Errorf("can't decode hideSuggestedAction#a2ef2b7f to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("hideSuggestedAction"); err != nil {
				return fmt.Errorf("unable to decode hideSuggestedAction#a2ef2b7f: %w", err)
			}
		case "action":
			value, err := DecodeTDLibJSONSuggestedAction(b)
			if err != nil {
				return fmt.Errorf("unable to decode hideSuggestedAction#a2ef2b7f: field action: %w", err)
			}
			h.Action = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetAction returns value of Action field.
func (h *HideSuggestedActionRequest) GetAction() (value SuggestedActionClass) {
	if h == nil {
		return
	}
	return h.Action
}

// HideSuggestedAction invokes method hideSuggestedAction#a2ef2b7f returning error if any.
func (c *Client) HideSuggestedAction(ctx context.Context, action SuggestedActionClass) error {
	var ok Ok

	request := &HideSuggestedActionRequest{
		Action: action,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
