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

// DeleteChatFolderInviteLinkRequest represents TL type `deleteChatFolderInviteLink#c890717e`.
type DeleteChatFolderInviteLinkRequest struct {
	// Chat folder identifier
	ChatFolderID int32
	// Invite link to be deleted
	InviteLink string
}

// DeleteChatFolderInviteLinkRequestTypeID is TL type id of DeleteChatFolderInviteLinkRequest.
const DeleteChatFolderInviteLinkRequestTypeID = 0xc890717e

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

func (d *DeleteChatFolderInviteLinkRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.ChatFolderID == 0) {
		return false
	}
	if !(d.InviteLink == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (d *DeleteChatFolderInviteLinkRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "deleteChatFolderInviteLink",
		ID:   DeleteChatFolderInviteLinkRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatFolderID",
			SchemaName: "chat_folder_id",
		},
		{
			Name:       "InviteLink",
			SchemaName: "invite_link",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *DeleteChatFolderInviteLinkRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteChatFolderInviteLink#c890717e as nil")
	}
	b.PutID(DeleteChatFolderInviteLinkRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeleteChatFolderInviteLinkRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteChatFolderInviteLink#c890717e as nil")
	}
	b.PutInt32(d.ChatFolderID)
	b.PutString(d.InviteLink)
	return nil
}

// Decode implements bin.Decoder.
func (d *DeleteChatFolderInviteLinkRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteChatFolderInviteLink#c890717e to nil")
	}
	if err := b.ConsumeID(DeleteChatFolderInviteLinkRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode deleteChatFolderInviteLink#c890717e: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *DeleteChatFolderInviteLinkRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteChatFolderInviteLink#c890717e to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode deleteChatFolderInviteLink#c890717e: field chat_folder_id: %w", err)
		}
		d.ChatFolderID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode deleteChatFolderInviteLink#c890717e: field invite_link: %w", err)
		}
		d.InviteLink = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeleteChatFolderInviteLinkRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteChatFolderInviteLink#c890717e as nil")
	}
	b.ObjStart()
	b.PutID("deleteChatFolderInviteLink")
	b.Comma()
	b.FieldStart("chat_folder_id")
	b.PutInt32(d.ChatFolderID)
	b.Comma()
	b.FieldStart("invite_link")
	b.PutString(d.InviteLink)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (d *DeleteChatFolderInviteLinkRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteChatFolderInviteLink#c890717e to nil")
	}

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

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

// GetInviteLink returns value of InviteLink field.
func (d *DeleteChatFolderInviteLinkRequest) GetInviteLink() (value string) {
	if d == nil {
		return
	}
	return d.InviteLink
}

// DeleteChatFolderInviteLink invokes method deleteChatFolderInviteLink#c890717e returning error if any.
func (c *Client) DeleteChatFolderInviteLink(ctx context.Context, request *DeleteChatFolderInviteLinkRequest) error {
	var ok Ok

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