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

// CancelRecoveryEmailAddressVerificationRequest represents TL type `cancelRecoveryEmailAddressVerification#a5988e8d`.
type CancelRecoveryEmailAddressVerificationRequest struct {
}

// CancelRecoveryEmailAddressVerificationRequestTypeID is TL type id of CancelRecoveryEmailAddressVerificationRequest.
const CancelRecoveryEmailAddressVerificationRequestTypeID = 0xa5988e8d

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

func (c *CancelRecoveryEmailAddressVerificationRequest) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CancelRecoveryEmailAddressVerificationRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode cancelRecoveryEmailAddressVerification#a5988e8d as nil")
	}
	b.PutID(CancelRecoveryEmailAddressVerificationRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CancelRecoveryEmailAddressVerificationRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode cancelRecoveryEmailAddressVerification#a5988e8d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CancelRecoveryEmailAddressVerificationRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode cancelRecoveryEmailAddressVerification#a5988e8d to nil")
	}
	if err := b.ConsumeID(CancelRecoveryEmailAddressVerificationRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode cancelRecoveryEmailAddressVerification#a5988e8d: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CancelRecoveryEmailAddressVerificationRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode cancelRecoveryEmailAddressVerification#a5988e8d to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CancelRecoveryEmailAddressVerificationRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode cancelRecoveryEmailAddressVerification#a5988e8d as nil")
	}
	b.ObjStart()
	b.PutID("cancelRecoveryEmailAddressVerification")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CancelRecoveryEmailAddressVerificationRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode cancelRecoveryEmailAddressVerification#a5988e8d to nil")
	}

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

// CancelRecoveryEmailAddressVerification invokes method cancelRecoveryEmailAddressVerification#a5988e8d returning error if any.
func (c *Client) CancelRecoveryEmailAddressVerification(ctx context.Context) (*PasswordState, error) {
	var result PasswordState

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