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

// AccountPasskeyRegistrationOptions represents TL type `account.passkeyRegistrationOptions#e16b5ce1`.
//
// See https://core.telegram.org/constructor/account.passkeyRegistrationOptions for reference.
type AccountPasskeyRegistrationOptions struct {
	// Options field of AccountPasskeyRegistrationOptions.
	Options DataJSON
}

// AccountPasskeyRegistrationOptionsTypeID is TL type id of AccountPasskeyRegistrationOptions.
const AccountPasskeyRegistrationOptionsTypeID = 0xe16b5ce1

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

func (p *AccountPasskeyRegistrationOptions) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.Options.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills AccountPasskeyRegistrationOptions from given interface.
func (p *AccountPasskeyRegistrationOptions) FillFrom(from interface {
	GetOptions() (value DataJSON)
}) {
	p.Options = from.GetOptions()
}

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

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

// TypeInfo returns info about TL type.
func (p *AccountPasskeyRegistrationOptions) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.passkeyRegistrationOptions",
		ID:   AccountPasskeyRegistrationOptionsTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Options",
			SchemaName: "options",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *AccountPasskeyRegistrationOptions) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode account.passkeyRegistrationOptions#e16b5ce1 as nil")
	}
	b.PutID(AccountPasskeyRegistrationOptionsTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *AccountPasskeyRegistrationOptions) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode account.passkeyRegistrationOptions#e16b5ce1 as nil")
	}
	if err := p.Options.Encode(b); err != nil {
		return fmt.Errorf("unable to encode account.passkeyRegistrationOptions#e16b5ce1: field options: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *AccountPasskeyRegistrationOptions) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode account.passkeyRegistrationOptions#e16b5ce1 to nil")
	}
	if err := b.ConsumeID(AccountPasskeyRegistrationOptionsTypeID); err != nil {
		return fmt.Errorf("unable to decode account.passkeyRegistrationOptions#e16b5ce1: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *AccountPasskeyRegistrationOptions) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode account.passkeyRegistrationOptions#e16b5ce1 to nil")
	}
	{
		if err := p.Options.Decode(b); err != nil {
			return fmt.Errorf("unable to decode account.passkeyRegistrationOptions#e16b5ce1: field options: %w", err)
		}
	}
	return nil
}

// GetOptions returns value of Options field.
func (p *AccountPasskeyRegistrationOptions) GetOptions() (value DataJSON) {
	if p == nil {
		return
	}
	return p.Options
}
