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

// GetApplicationDownloadLinkRequest represents TL type `getApplicationDownloadLink#6ad2fc4`.
type GetApplicationDownloadLinkRequest struct {
}

// GetApplicationDownloadLinkRequestTypeID is TL type id of GetApplicationDownloadLinkRequest.
const GetApplicationDownloadLinkRequestTypeID = 0x6ad2fc4

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GetApplicationDownloadLinkRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getApplicationDownloadLink#6ad2fc4 as nil")
	}
	b.PutID(GetApplicationDownloadLinkRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

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

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

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

// GetApplicationDownloadLink invokes method getApplicationDownloadLink#6ad2fc4 returning error if any.
func (c *Client) GetApplicationDownloadLink(ctx context.Context) (*HTTPURL, error) {
	var result HTTPURL

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