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

// AuthPasskeyLoginOptions represents TL type `auth.passkeyLoginOptions#e2037789`.
//
// See https://core.telegram.org/constructor/auth.passkeyLoginOptions for reference.
type AuthPasskeyLoginOptions struct {
	// Options field of AuthPasskeyLoginOptions.
	Options DataJSON
}

// AuthPasskeyLoginOptionsTypeID is TL type id of AuthPasskeyLoginOptions.
const AuthPasskeyLoginOptionsTypeID = 0xe2037789

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

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

	return true
}

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

// FillFrom fills AuthPasskeyLoginOptions from given interface.
func (p *AuthPasskeyLoginOptions) 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 (*AuthPasskeyLoginOptions) TypeID() uint32 {
	return AuthPasskeyLoginOptionsTypeID
}

// TypeName returns name of type in TL schema.
func (*AuthPasskeyLoginOptions) TypeName() string {
	return "auth.passkeyLoginOptions"
}

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

// Encode implements bin.Encoder.
func (p *AuthPasskeyLoginOptions) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode auth.passkeyLoginOptions#e2037789 as nil")
	}
	b.PutID(AuthPasskeyLoginOptionsTypeID)
	return p.EncodeBare(b)
}

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

// Decode implements bin.Decoder.
func (p *AuthPasskeyLoginOptions) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode auth.passkeyLoginOptions#e2037789 to nil")
	}
	if err := b.ConsumeID(AuthPasskeyLoginOptionsTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.passkeyLoginOptions#e2037789: %w", err)
	}
	return p.DecodeBare(b)
}

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

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