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

// SetPaidMessageReactionTypeRequest represents TL type `setPaidMessageReactionType#ce8832ae`.
type SetPaidMessageReactionTypeRequest struct {
	// Identifier of the chat to which the message belongs
	ChatID int64
	// Identifier of the message
	MessageID int64
	// New type of the paid reaction
	Type PaidReactionTypeClass
}

// SetPaidMessageReactionTypeRequestTypeID is TL type id of SetPaidMessageReactionTypeRequest.
const SetPaidMessageReactionTypeRequestTypeID = 0xce8832ae

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

func (s *SetPaidMessageReactionTypeRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.MessageID == 0) {
		return false
	}
	if !(s.Type == nil) {
		return false
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (s *SetPaidMessageReactionTypeRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setPaidMessageReactionType#ce8832ae as nil")
	}
	b.PutID(SetPaidMessageReactionTypeRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetPaidMessageReactionTypeRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setPaidMessageReactionType#ce8832ae as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutInt53(s.MessageID)
	if s.Type == nil {
		return fmt.Errorf("unable to encode setPaidMessageReactionType#ce8832ae: field type is nil")
	}
	if err := s.Type.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setPaidMessageReactionType#ce8832ae: field type: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SetPaidMessageReactionTypeRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setPaidMessageReactionType#ce8832ae to nil")
	}
	if err := b.ConsumeID(SetPaidMessageReactionTypeRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setPaidMessageReactionType#ce8832ae: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetPaidMessageReactionTypeRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setPaidMessageReactionType#ce8832ae to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setPaidMessageReactionType#ce8832ae: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setPaidMessageReactionType#ce8832ae: field message_id: %w", err)
		}
		s.MessageID = value
	}
	{
		value, err := DecodePaidReactionType(b)
		if err != nil {
			return fmt.Errorf("unable to decode setPaidMessageReactionType#ce8832ae: field type: %w", err)
		}
		s.Type = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetPaidMessageReactionTypeRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setPaidMessageReactionType#ce8832ae as nil")
	}
	b.ObjStart()
	b.PutID("setPaidMessageReactionType")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("message_id")
	b.PutInt53(s.MessageID)
	b.Comma()
	b.FieldStart("type")
	if s.Type == nil {
		return fmt.Errorf("unable to encode setPaidMessageReactionType#ce8832ae: field type is nil")
	}
	if err := s.Type.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setPaidMessageReactionType#ce8832ae: field type: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetPaidMessageReactionTypeRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setPaidMessageReactionType#ce8832ae to nil")
	}

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

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

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

// GetType returns value of Type field.
func (s *SetPaidMessageReactionTypeRequest) GetType() (value PaidReactionTypeClass) {
	if s == nil {
		return
	}
	return s.Type
}

// SetPaidMessageReactionType invokes method setPaidMessageReactionType#ce8832ae returning error if any.
func (c *Client) SetPaidMessageReactionType(ctx context.Context, request *SetPaidMessageReactionTypeRequest) error {
	var ok Ok

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