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

// ResetPasswordRequest represents TL type `resetPassword#dc9e8c9d`.
type ResetPasswordRequest struct {
}

// ResetPasswordRequestTypeID is TL type id of ResetPasswordRequest.
const ResetPasswordRequestTypeID = 0xdc9e8c9d

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

func (r *ResetPasswordRequest) Zero() bool {
	if r == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (r *ResetPasswordRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode resetPassword#dc9e8c9d as nil")
	}
	b.PutID(ResetPasswordRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ResetPasswordRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode resetPassword#dc9e8c9d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (r *ResetPasswordRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode resetPassword#dc9e8c9d to nil")
	}
	if err := b.ConsumeID(ResetPasswordRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode resetPassword#dc9e8c9d: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *ResetPasswordRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode resetPassword#dc9e8c9d to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *ResetPasswordRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode resetPassword#dc9e8c9d to nil")
	}

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

// ResetPassword invokes method resetPassword#dc9e8c9d returning error if any.
func (c *Client) ResetPassword(ctx context.Context) (ResetPasswordResultClass, error) {
	var result ResetPasswordResultBox

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