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

// GetAutosaveSettingsRequest represents TL type `getAutosaveSettings#7f53f22a`.
type GetAutosaveSettingsRequest struct {
}

// GetAutosaveSettingsRequestTypeID is TL type id of GetAutosaveSettingsRequest.
const GetAutosaveSettingsRequestTypeID = 0x7f53f22a

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

func (g *GetAutosaveSettingsRequest) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetAutosaveSettingsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getAutosaveSettings",
		ID:   GetAutosaveSettingsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetAutosaveSettingsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getAutosaveSettings#7f53f22a as nil")
	}
	b.PutID(GetAutosaveSettingsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetAutosaveSettingsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getAutosaveSettings#7f53f22a as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GetAutosaveSettingsRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getAutosaveSettings#7f53f22a to nil")
	}
	if err := b.ConsumeID(GetAutosaveSettingsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode getAutosaveSettings#7f53f22a: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GetAutosaveSettingsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getAutosaveSettings#7f53f22a to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetAutosaveSettingsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getAutosaveSettings#7f53f22a as nil")
	}
	b.ObjStart()
	b.PutID("getAutosaveSettings")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetAutosaveSettingsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getAutosaveSettings#7f53f22a to nil")
	}

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

// GetAutosaveSettings invokes method getAutosaveSettings#7f53f22a returning error if any.
func (c *Client) GetAutosaveSettings(ctx context.Context) (*AutosaveSettings, error) {
	var result AutosaveSettings

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