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

// ClickAnimatedEmojiMessageRequest represents TL type `clickAnimatedEmojiMessage#bb17662`.
type ClickAnimatedEmojiMessageRequest struct {
	// Chat identifier of the message
	ChatID int64
	// Identifier of the clicked message
	MessageID int64
}

// ClickAnimatedEmojiMessageRequestTypeID is TL type id of ClickAnimatedEmojiMessageRequest.
const ClickAnimatedEmojiMessageRequestTypeID = 0xbb17662

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

func (c *ClickAnimatedEmojiMessageRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.ChatID == 0) {
		return false
	}
	if !(c.MessageID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *ClickAnimatedEmojiMessageRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "clickAnimatedEmojiMessage",
		ID:   ClickAnimatedEmojiMessageRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageID",
			SchemaName: "message_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ClickAnimatedEmojiMessageRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clickAnimatedEmojiMessage#bb17662 as nil")
	}
	b.PutID(ClickAnimatedEmojiMessageRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ClickAnimatedEmojiMessageRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clickAnimatedEmojiMessage#bb17662 as nil")
	}
	b.PutInt53(c.ChatID)
	b.PutInt53(c.MessageID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (c *ClickAnimatedEmojiMessageRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode clickAnimatedEmojiMessage#bb17662 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode clickAnimatedEmojiMessage#bb17662: field chat_id: %w", err)
		}
		c.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode clickAnimatedEmojiMessage#bb17662: field message_id: %w", err)
		}
		c.MessageID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ClickAnimatedEmojiMessageRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode clickAnimatedEmojiMessage#bb17662 as nil")
	}
	b.ObjStart()
	b.PutID("clickAnimatedEmojiMessage")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(c.ChatID)
	b.Comma()
	b.FieldStart("message_id")
	b.PutInt53(c.MessageID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("clickAnimatedEmojiMessage"); err != nil {
				return fmt.Errorf("unable to decode clickAnimatedEmojiMessage#bb17662: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode clickAnimatedEmojiMessage#bb17662: field chat_id: %w", err)
			}
			c.ChatID = value
		case "message_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode clickAnimatedEmojiMessage#bb17662: field message_id: %w", err)
			}
			c.MessageID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (c *ClickAnimatedEmojiMessageRequest) GetChatID() (value int64) {
	if c == nil {
		return
	}
	return c.ChatID
}

// GetMessageID returns value of MessageID field.
func (c *ClickAnimatedEmojiMessageRequest) GetMessageID() (value int64) {
	if c == nil {
		return
	}
	return c.MessageID
}

// ClickAnimatedEmojiMessage invokes method clickAnimatedEmojiMessage#bb17662 returning error if any.
func (c *Client) ClickAnimatedEmojiMessage(ctx context.Context, request *ClickAnimatedEmojiMessageRequest) (*Sticker, error) {
	var result Sticker

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