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

// InputPasskeyResponseRegister represents TL type `inputPasskeyResponseRegister#3e63935c`.
//
// See https://core.telegram.org/constructor/inputPasskeyResponseRegister for reference.
type InputPasskeyResponseRegister struct {
	// ClientData field of InputPasskeyResponseRegister.
	ClientData DataJSON
	// AttestationData field of InputPasskeyResponseRegister.
	AttestationData []byte
}

// InputPasskeyResponseRegisterTypeID is TL type id of InputPasskeyResponseRegister.
const InputPasskeyResponseRegisterTypeID = 0x3e63935c

// construct implements constructor of InputPasskeyResponseClass.
func (i InputPasskeyResponseRegister) construct() InputPasskeyResponseClass { return &i }

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

	_ InputPasskeyResponseClass = &InputPasskeyResponseRegister{}
)

func (i *InputPasskeyResponseRegister) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.ClientData.Zero()) {
		return false
	}
	if !(i.AttestationData == nil) {
		return false
	}

	return true
}

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

// FillFrom fills InputPasskeyResponseRegister from given interface.
func (i *InputPasskeyResponseRegister) FillFrom(from interface {
	GetClientData() (value DataJSON)
	GetAttestationData() (value []byte)
}) {
	i.ClientData = from.GetClientData()
	i.AttestationData = from.GetAttestationData()
}

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

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

// TypeInfo returns info about TL type.
func (i *InputPasskeyResponseRegister) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputPasskeyResponseRegister",
		ID:   InputPasskeyResponseRegisterTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ClientData",
			SchemaName: "client_data",
		},
		{
			Name:       "AttestationData",
			SchemaName: "attestation_data",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputPasskeyResponseRegister) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputPasskeyResponseRegister#3e63935c as nil")
	}
	b.PutID(InputPasskeyResponseRegisterTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputPasskeyResponseRegister) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputPasskeyResponseRegister#3e63935c as nil")
	}
	if err := i.ClientData.Encode(b); err != nil {
		return fmt.Errorf("unable to encode inputPasskeyResponseRegister#3e63935c: field client_data: %w", err)
	}
	b.PutBytes(i.AttestationData)
	return nil
}

// Decode implements bin.Decoder.
func (i *InputPasskeyResponseRegister) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputPasskeyResponseRegister#3e63935c to nil")
	}
	if err := b.ConsumeID(InputPasskeyResponseRegisterTypeID); err != nil {
		return fmt.Errorf("unable to decode inputPasskeyResponseRegister#3e63935c: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InputPasskeyResponseRegister) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputPasskeyResponseRegister#3e63935c to nil")
	}
	{
		if err := i.ClientData.Decode(b); err != nil {
			return fmt.Errorf("unable to decode inputPasskeyResponseRegister#3e63935c: field client_data: %w", err)
		}
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode inputPasskeyResponseRegister#3e63935c: field attestation_data: %w", err)
		}
		i.AttestationData = value
	}
	return nil
}

// GetClientData returns value of ClientData field.
func (i *InputPasskeyResponseRegister) GetClientData() (value DataJSON) {
	if i == nil {
		return
	}
	return i.ClientData
}

// GetAttestationData returns value of AttestationData field.
func (i *InputPasskeyResponseRegister) GetAttestationData() (value []byte) {
	if i == nil {
		return
	}
	return i.AttestationData
}

// InputPasskeyResponseLogin represents TL type `inputPasskeyResponseLogin#c31fc14a`.
//
// See https://core.telegram.org/constructor/inputPasskeyResponseLogin for reference.
type InputPasskeyResponseLogin struct {
	// ClientData field of InputPasskeyResponseLogin.
	ClientData DataJSON
	// AuthenticatorData field of InputPasskeyResponseLogin.
	AuthenticatorData []byte
	// Signature field of InputPasskeyResponseLogin.
	Signature []byte
	// UserHandle field of InputPasskeyResponseLogin.
	UserHandle string
}

// InputPasskeyResponseLoginTypeID is TL type id of InputPasskeyResponseLogin.
const InputPasskeyResponseLoginTypeID = 0xc31fc14a

// construct implements constructor of InputPasskeyResponseClass.
func (i InputPasskeyResponseLogin) construct() InputPasskeyResponseClass { return &i }

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

	_ InputPasskeyResponseClass = &InputPasskeyResponseLogin{}
)

func (i *InputPasskeyResponseLogin) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.ClientData.Zero()) {
		return false
	}
	if !(i.AuthenticatorData == nil) {
		return false
	}
	if !(i.Signature == nil) {
		return false
	}
	if !(i.UserHandle == "") {
		return false
	}

	return true
}

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

// FillFrom fills InputPasskeyResponseLogin from given interface.
func (i *InputPasskeyResponseLogin) FillFrom(from interface {
	GetClientData() (value DataJSON)
	GetAuthenticatorData() (value []byte)
	GetSignature() (value []byte)
	GetUserHandle() (value string)
}) {
	i.ClientData = from.GetClientData()
	i.AuthenticatorData = from.GetAuthenticatorData()
	i.Signature = from.GetSignature()
	i.UserHandle = from.GetUserHandle()
}

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

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

// TypeInfo returns info about TL type.
func (i *InputPasskeyResponseLogin) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputPasskeyResponseLogin",
		ID:   InputPasskeyResponseLoginTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ClientData",
			SchemaName: "client_data",
		},
		{
			Name:       "AuthenticatorData",
			SchemaName: "authenticator_data",
		},
		{
			Name:       "Signature",
			SchemaName: "signature",
		},
		{
			Name:       "UserHandle",
			SchemaName: "user_handle",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputPasskeyResponseLogin) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputPasskeyResponseLogin#c31fc14a as nil")
	}
	b.PutID(InputPasskeyResponseLoginTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputPasskeyResponseLogin) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputPasskeyResponseLogin#c31fc14a as nil")
	}
	if err := i.ClientData.Encode(b); err != nil {
		return fmt.Errorf("unable to encode inputPasskeyResponseLogin#c31fc14a: field client_data: %w", err)
	}
	b.PutBytes(i.AuthenticatorData)
	b.PutBytes(i.Signature)
	b.PutString(i.UserHandle)
	return nil
}

// Decode implements bin.Decoder.
func (i *InputPasskeyResponseLogin) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputPasskeyResponseLogin#c31fc14a to nil")
	}
	if err := b.ConsumeID(InputPasskeyResponseLoginTypeID); err != nil {
		return fmt.Errorf("unable to decode inputPasskeyResponseLogin#c31fc14a: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InputPasskeyResponseLogin) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputPasskeyResponseLogin#c31fc14a to nil")
	}
	{
		if err := i.ClientData.Decode(b); err != nil {
			return fmt.Errorf("unable to decode inputPasskeyResponseLogin#c31fc14a: field client_data: %w", err)
		}
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode inputPasskeyResponseLogin#c31fc14a: field authenticator_data: %w", err)
		}
		i.AuthenticatorData = value
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode inputPasskeyResponseLogin#c31fc14a: field signature: %w", err)
		}
		i.Signature = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode inputPasskeyResponseLogin#c31fc14a: field user_handle: %w", err)
		}
		i.UserHandle = value
	}
	return nil
}

// GetClientData returns value of ClientData field.
func (i *InputPasskeyResponseLogin) GetClientData() (value DataJSON) {
	if i == nil {
		return
	}
	return i.ClientData
}

// GetAuthenticatorData returns value of AuthenticatorData field.
func (i *InputPasskeyResponseLogin) GetAuthenticatorData() (value []byte) {
	if i == nil {
		return
	}
	return i.AuthenticatorData
}

// GetSignature returns value of Signature field.
func (i *InputPasskeyResponseLogin) GetSignature() (value []byte) {
	if i == nil {
		return
	}
	return i.Signature
}

// GetUserHandle returns value of UserHandle field.
func (i *InputPasskeyResponseLogin) GetUserHandle() (value string) {
	if i == nil {
		return
	}
	return i.UserHandle
}

// InputPasskeyResponseClassName is schema name of InputPasskeyResponseClass.
const InputPasskeyResponseClassName = "InputPasskeyResponse"

// InputPasskeyResponseClass represents InputPasskeyResponse generic type.
//
// See https://core.telegram.org/type/InputPasskeyResponse for reference.
//
// Example:
//
//	g, err := tg.DecodeInputPasskeyResponse(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.InputPasskeyResponseRegister: // inputPasskeyResponseRegister#3e63935c
//	case *tg.InputPasskeyResponseLogin: // inputPasskeyResponseLogin#c31fc14a
//	default: panic(v)
//	}
type InputPasskeyResponseClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() InputPasskeyResponseClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// ClientData field of InputPasskeyResponseRegister.
	GetClientData() (value DataJSON)
}

// DecodeInputPasskeyResponse implements binary de-serialization for InputPasskeyResponseClass.
func DecodeInputPasskeyResponse(buf *bin.Buffer) (InputPasskeyResponseClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case InputPasskeyResponseRegisterTypeID:
		// Decoding inputPasskeyResponseRegister#3e63935c.
		v := InputPasskeyResponseRegister{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InputPasskeyResponseClass: %w", err)
		}
		return &v, nil
	case InputPasskeyResponseLoginTypeID:
		// Decoding inputPasskeyResponseLogin#c31fc14a.
		v := InputPasskeyResponseLogin{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InputPasskeyResponseClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode InputPasskeyResponseClass: %w", bin.NewUnexpectedID(id))
	}
}

// InputPasskeyResponse boxes the InputPasskeyResponseClass providing a helper.
type InputPasskeyResponseBox struct {
	InputPasskeyResponse InputPasskeyResponseClass
}

// Decode implements bin.Decoder for InputPasskeyResponseBox.
func (b *InputPasskeyResponseBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode InputPasskeyResponseBox to nil")
	}
	v, err := DecodeInputPasskeyResponse(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.InputPasskeyResponse = v
	return nil
}

// Encode implements bin.Encode for InputPasskeyResponseBox.
func (b *InputPasskeyResponseBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.InputPasskeyResponse == nil {
		return fmt.Errorf("unable to encode InputPasskeyResponseClass as nil")
	}
	return b.InputPasskeyResponse.Encode(buf)
}
