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

// SetArchiveChatListSettingsRequest represents TL type `setArchiveChatListSettings#cb454c0a`.
type SetArchiveChatListSettingsRequest struct {
	// New settings
	Settings ArchiveChatListSettings
}

// SetArchiveChatListSettingsRequestTypeID is TL type id of SetArchiveChatListSettingsRequest.
const SetArchiveChatListSettingsRequestTypeID = 0xcb454c0a

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetArchiveChatListSettingsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setArchiveChatListSettings",
		ID:   SetArchiveChatListSettingsRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Settings",
			SchemaName: "settings",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetArchiveChatListSettingsRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setArchiveChatListSettings#cb454c0a as nil")
	}
	b.PutID(SetArchiveChatListSettingsRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetArchiveChatListSettingsRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setArchiveChatListSettings#cb454c0a as nil")
	}
	if err := s.Settings.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setArchiveChatListSettings#cb454c0a: field settings: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetArchiveChatListSettingsRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setArchiveChatListSettings#cb454c0a to nil")
	}
	{
		if err := s.Settings.Decode(b); err != nil {
			return fmt.Errorf("unable to decode setArchiveChatListSettings#cb454c0a: field settings: %w", err)
		}
	}
	return nil
}

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

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

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

// GetSettings returns value of Settings field.
func (s *SetArchiveChatListSettingsRequest) GetSettings() (value ArchiveChatListSettings) {
	if s == nil {
		return
	}
	return s.Settings
}

// SetArchiveChatListSettings invokes method setArchiveChatListSettings#cb454c0a returning error if any.
func (c *Client) SetArchiveChatListSettings(ctx context.Context, settings ArchiveChatListSettings) error {
	var ok Ok

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