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

// GetBusinessChatLinksRequest represents TL type `getBusinessChatLinks#2a562157`.
type GetBusinessChatLinksRequest struct {
}

// GetBusinessChatLinksRequestTypeID is TL type id of GetBusinessChatLinksRequest.
const GetBusinessChatLinksRequestTypeID = 0x2a562157

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GetBusinessChatLinksRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getBusinessChatLinks#2a562157 as nil")
	}
	b.PutID(GetBusinessChatLinksRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

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

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

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

// GetBusinessChatLinks invokes method getBusinessChatLinks#2a562157 returning error if any.
func (c *Client) GetBusinessChatLinks(ctx context.Context) (*BusinessChatLinks, error) {
	var result BusinessChatLinks

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