// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// AccountDeletePasskeyRequest represents TL type `account.deletePasskey#f5b5563f`.
//
// See https://core.telegram.org/method/account.deletePasskey for reference.
type AccountDeletePasskeyRequest struct {
	// ID field of AccountDeletePasskeyRequest.
	ID string
}

// AccountDeletePasskeyRequestTypeID is TL type id of AccountDeletePasskeyRequest.
const AccountDeletePasskeyRequestTypeID = 0xf5b5563f

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

func (d *AccountDeletePasskeyRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.ID == "") {
		return false
	}

	return true
}

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

// FillFrom fills AccountDeletePasskeyRequest from given interface.
func (d *AccountDeletePasskeyRequest) FillFrom(from interface {
	GetID() (value string)
}) {
	d.ID = from.GetID()
}

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

// TypeName returns name of type in TL schema.
func (*AccountDeletePasskeyRequest) TypeName() string {
	return "account.deletePasskey"
}

// TypeInfo returns info about TL type.
func (d *AccountDeletePasskeyRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.deletePasskey",
		ID:   AccountDeletePasskeyRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *AccountDeletePasskeyRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode account.deletePasskey#f5b5563f as nil")
	}
	b.PutID(AccountDeletePasskeyRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *AccountDeletePasskeyRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode account.deletePasskey#f5b5563f as nil")
	}
	b.PutString(d.ID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (d *AccountDeletePasskeyRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode account.deletePasskey#f5b5563f to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode account.deletePasskey#f5b5563f: field id: %w", err)
		}
		d.ID = value
	}
	return nil
}

// GetID returns value of ID field.
func (d *AccountDeletePasskeyRequest) GetID() (value string) {
	if d == nil {
		return
	}
	return d.ID
}

// AccountDeletePasskey invokes method account.deletePasskey#f5b5563f returning error if any.
//
// See https://core.telegram.org/method/account.deletePasskey for reference.
func (c *Client) AccountDeletePasskey(ctx context.Context, id string) (bool, error) {
	var result BoolBox

	request := &AccountDeletePasskeyRequest{
		ID: id,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
