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

// SetReactionNotificationSettingsRequest represents TL type `setReactionNotificationSettings#46b2d495`.
type SetReactionNotificationSettingsRequest struct {
	// The new notification settings for reactions
	NotificationSettings ReactionNotificationSettings
}

// SetReactionNotificationSettingsRequestTypeID is TL type id of SetReactionNotificationSettingsRequest.
const SetReactionNotificationSettingsRequestTypeID = 0x46b2d495

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

func (s *SetReactionNotificationSettingsRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.NotificationSettings.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetReactionNotificationSettingsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setReactionNotificationSettings",
		ID:   SetReactionNotificationSettingsRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "NotificationSettings",
			SchemaName: "notification_settings",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetReactionNotificationSettingsRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setReactionNotificationSettings#46b2d495 as nil")
	}
	b.PutID(SetReactionNotificationSettingsRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetReactionNotificationSettingsRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setReactionNotificationSettings#46b2d495 as nil")
	}
	if err := s.NotificationSettings.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setReactionNotificationSettings#46b2d495: field notification_settings: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetReactionNotificationSettingsRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setReactionNotificationSettings#46b2d495 to nil")
	}
	{
		if err := s.NotificationSettings.Decode(b); err != nil {
			return fmt.Errorf("unable to decode setReactionNotificationSettings#46b2d495: field notification_settings: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetReactionNotificationSettingsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setReactionNotificationSettings#46b2d495 as nil")
	}
	b.ObjStart()
	b.PutID("setReactionNotificationSettings")
	b.Comma()
	b.FieldStart("notification_settings")
	if err := s.NotificationSettings.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setReactionNotificationSettings#46b2d495: field notification_settings: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setReactionNotificationSettings"); err != nil {
				return fmt.Errorf("unable to decode setReactionNotificationSettings#46b2d495: %w", err)
			}
		case "notification_settings":
			if err := s.NotificationSettings.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode setReactionNotificationSettings#46b2d495: field notification_settings: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetNotificationSettings returns value of NotificationSettings field.
func (s *SetReactionNotificationSettingsRequest) GetNotificationSettings() (value ReactionNotificationSettings) {
	if s == nil {
		return
	}
	return s.NotificationSettings
}

// SetReactionNotificationSettings invokes method setReactionNotificationSettings#46b2d495 returning error if any.
func (c *Client) SetReactionNotificationSettings(ctx context.Context, notificationsettings ReactionNotificationSettings) error {
	var ok Ok

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