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

// GetApplicationConfigRequest represents TL type `getApplicationConfig#93550682`.
type GetApplicationConfigRequest struct {
}

// GetApplicationConfigRequestTypeID is TL type id of GetApplicationConfigRequest.
const GetApplicationConfigRequestTypeID = 0x93550682

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GetApplicationConfigRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getApplicationConfig#93550682 as nil")
	}
	b.PutID(GetApplicationConfigRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

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

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

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

// GetApplicationConfig invokes method getApplicationConfig#93550682 returning error if any.
func (c *Client) GetApplicationConfig(ctx context.Context) (JSONValueClass, error) {
	var result JSONValueBox

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