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

// DeleteSavedCredentialsRequest represents TL type `deleteSavedCredentials#314056d2`.
type DeleteSavedCredentialsRequest struct {
}

// DeleteSavedCredentialsRequestTypeID is TL type id of DeleteSavedCredentialsRequest.
const DeleteSavedCredentialsRequestTypeID = 0x314056d2

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

func (d *DeleteSavedCredentialsRequest) Zero() bool {
	if d == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (d *DeleteSavedCredentialsRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteSavedCredentials#314056d2 as nil")
	}
	b.PutID(DeleteSavedCredentialsRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeleteSavedCredentialsRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteSavedCredentials#314056d2 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (d *DeleteSavedCredentialsRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteSavedCredentials#314056d2 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeleteSavedCredentialsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteSavedCredentials#314056d2 as nil")
	}
	b.ObjStart()
	b.PutID("deleteSavedCredentials")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// DeleteSavedCredentials invokes method deleteSavedCredentials#314056d2 returning error if any.
func (c *Client) DeleteSavedCredentials(ctx context.Context) error {
	var ok Ok

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