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

// SetForumTopicNotificationSettingsRequest represents TL type `setForumTopicNotificationSettings#1f433467`.
type SetForumTopicNotificationSettingsRequest struct {
	// Chat identifier
	ChatID int64
	// Message thread identifier of the forum topic
	MessageThreadID int64
	// New notification settings for the forum topic. If the topic is muted for more than 366
	// days, it is considered to be muted forever
	NotificationSettings ChatNotificationSettings
}

// SetForumTopicNotificationSettingsRequestTypeID is TL type id of SetForumTopicNotificationSettingsRequest.
const SetForumTopicNotificationSettingsRequestTypeID = 0x1f433467

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

func (s *SetForumTopicNotificationSettingsRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.MessageThreadID == 0) {
		return false
	}
	if !(s.NotificationSettings.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetForumTopicNotificationSettingsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setForumTopicNotificationSettings",
		ID:   SetForumTopicNotificationSettingsRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageThreadID",
			SchemaName: "message_thread_id",
		},
		{
			Name:       "NotificationSettings",
			SchemaName: "notification_settings",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetForumTopicNotificationSettingsRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setForumTopicNotificationSettings#1f433467 as nil")
	}
	b.PutID(SetForumTopicNotificationSettingsRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetForumTopicNotificationSettingsRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setForumTopicNotificationSettings#1f433467 as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutInt53(s.MessageThreadID)
	if err := s.NotificationSettings.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setForumTopicNotificationSettings#1f433467: field notification_settings: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetForumTopicNotificationSettingsRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setForumTopicNotificationSettings#1f433467 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setForumTopicNotificationSettings#1f433467: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setForumTopicNotificationSettings#1f433467: field message_thread_id: %w", err)
		}
		s.MessageThreadID = value
	}
	{
		if err := s.NotificationSettings.Decode(b); err != nil {
			return fmt.Errorf("unable to decode setForumTopicNotificationSettings#1f433467: field notification_settings: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetForumTopicNotificationSettingsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setForumTopicNotificationSettings#1f433467 as nil")
	}
	b.ObjStart()
	b.PutID("setForumTopicNotificationSettings")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("message_thread_id")
	b.PutInt53(s.MessageThreadID)
	b.Comma()
	b.FieldStart("notification_settings")
	if err := s.NotificationSettings.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setForumTopicNotificationSettings#1f433467: field notification_settings: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setForumTopicNotificationSettings"); err != nil {
				return fmt.Errorf("unable to decode setForumTopicNotificationSettings#1f433467: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setForumTopicNotificationSettings#1f433467: field chat_id: %w", err)
			}
			s.ChatID = value
		case "message_thread_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setForumTopicNotificationSettings#1f433467: field message_thread_id: %w", err)
			}
			s.MessageThreadID = value
		case "notification_settings":
			if err := s.NotificationSettings.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode setForumTopicNotificationSettings#1f433467: field notification_settings: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetMessageThreadID returns value of MessageThreadID field.
func (s *SetForumTopicNotificationSettingsRequest) GetMessageThreadID() (value int64) {
	if s == nil {
		return
	}
	return s.MessageThreadID
}

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

// SetForumTopicNotificationSettings invokes method setForumTopicNotificationSettings#1f433467 returning error if any.
func (c *Client) SetForumTopicNotificationSettings(ctx context.Context, request *SetForumTopicNotificationSettingsRequest) error {
	var ok Ok

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