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

// SetReadDatePrivacySettingsRequest represents TL type `setReadDatePrivacySettings#1d7086b6`.
type SetReadDatePrivacySettingsRequest struct {
	// New settings
	Settings ReadDatePrivacySettings
}

// SetReadDatePrivacySettingsRequestTypeID is TL type id of SetReadDatePrivacySettingsRequest.
const SetReadDatePrivacySettingsRequestTypeID = 0x1d7086b6

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

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

	return true
}

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

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

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

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

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

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

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

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

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

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

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

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

// SetReadDatePrivacySettings invokes method setReadDatePrivacySettings#1d7086b6 returning error if any.
func (c *Client) SetReadDatePrivacySettings(ctx context.Context, settings ReadDatePrivacySettings) error {
	var ok Ok

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