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

// GetChatFolderInviteLinksRequest represents TL type `getChatFolderInviteLinks#139d5be0`.
type GetChatFolderInviteLinksRequest struct {
	// Chat folder identifier
	ChatFolderID int32
}

// GetChatFolderInviteLinksRequestTypeID is TL type id of GetChatFolderInviteLinksRequest.
const GetChatFolderInviteLinksRequestTypeID = 0x139d5be0

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

func (g *GetChatFolderInviteLinksRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.ChatFolderID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetChatFolderInviteLinksRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getChatFolderInviteLinks",
		ID:   GetChatFolderInviteLinksRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatFolderID",
			SchemaName: "chat_folder_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetChatFolderInviteLinksRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatFolderInviteLinks#139d5be0 as nil")
	}
	b.PutID(GetChatFolderInviteLinksRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetChatFolderInviteLinksRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatFolderInviteLinks#139d5be0 as nil")
	}
	b.PutInt32(g.ChatFolderID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetChatFolderInviteLinksRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getChatFolderInviteLinks#139d5be0 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode getChatFolderInviteLinks#139d5be0: field chat_folder_id: %w", err)
		}
		g.ChatFolderID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetChatFolderInviteLinksRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatFolderInviteLinks#139d5be0 as nil")
	}
	b.ObjStart()
	b.PutID("getChatFolderInviteLinks")
	b.Comma()
	b.FieldStart("chat_folder_id")
	b.PutInt32(g.ChatFolderID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getChatFolderInviteLinks"); err != nil {
				return fmt.Errorf("unable to decode getChatFolderInviteLinks#139d5be0: %w", err)
			}
		case "chat_folder_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode getChatFolderInviteLinks#139d5be0: field chat_folder_id: %w", err)
			}
			g.ChatFolderID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatFolderID returns value of ChatFolderID field.
func (g *GetChatFolderInviteLinksRequest) GetChatFolderID() (value int32) {
	if g == nil {
		return
	}
	return g.ChatFolderID
}

// GetChatFolderInviteLinks invokes method getChatFolderInviteLinks#139d5be0 returning error if any.
func (c *Client) GetChatFolderInviteLinks(ctx context.Context, chatfolderid int32) (*ChatFolderInviteLinks, error) {
	var result ChatFolderInviteLinks

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