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

// SetNewChatPrivacySettingsRequest represents TL type `setNewChatPrivacySettings#69bf374f`.
type SetNewChatPrivacySettingsRequest struct {
	// New settings
	Settings NewChatPrivacySettings
}

// SetNewChatPrivacySettingsRequestTypeID is TL type id of SetNewChatPrivacySettingsRequest.
const SetNewChatPrivacySettingsRequestTypeID = 0x69bf374f

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (s *SetNewChatPrivacySettingsRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setNewChatPrivacySettings#69bf374f as nil")
	}
	b.PutID(SetNewChatPrivacySettingsRequestTypeID)
	return s.EncodeBare(b)
}

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

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

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

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

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

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

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

// SetNewChatPrivacySettings invokes method setNewChatPrivacySettings#69bf374f returning error if any.
func (c *Client) SetNewChatPrivacySettings(ctx context.Context, settings NewChatPrivacySettings) error {
	var ok Ok

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