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

// ReportAuthenticationCodeMissingRequest represents TL type `reportAuthenticationCodeMissing#91efce48`.
type ReportAuthenticationCodeMissingRequest struct {
	// Current mobile network code
	MobileNetworkCode string
}

// ReportAuthenticationCodeMissingRequestTypeID is TL type id of ReportAuthenticationCodeMissingRequest.
const ReportAuthenticationCodeMissingRequestTypeID = 0x91efce48

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

func (r *ReportAuthenticationCodeMissingRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.MobileNetworkCode == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *ReportAuthenticationCodeMissingRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "reportAuthenticationCodeMissing",
		ID:   ReportAuthenticationCodeMissingRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "MobileNetworkCode",
			SchemaName: "mobile_network_code",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *ReportAuthenticationCodeMissingRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reportAuthenticationCodeMissing#91efce48 as nil")
	}
	b.PutID(ReportAuthenticationCodeMissingRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ReportAuthenticationCodeMissingRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reportAuthenticationCodeMissing#91efce48 as nil")
	}
	b.PutString(r.MobileNetworkCode)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (r *ReportAuthenticationCodeMissingRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reportAuthenticationCodeMissing#91efce48 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode reportAuthenticationCodeMissing#91efce48: field mobile_network_code: %w", err)
		}
		r.MobileNetworkCode = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReportAuthenticationCodeMissingRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode reportAuthenticationCodeMissing#91efce48 as nil")
	}
	b.ObjStart()
	b.PutID("reportAuthenticationCodeMissing")
	b.Comma()
	b.FieldStart("mobile_network_code")
	b.PutString(r.MobileNetworkCode)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("reportAuthenticationCodeMissing"); err != nil {
				return fmt.Errorf("unable to decode reportAuthenticationCodeMissing#91efce48: %w", err)
			}
		case "mobile_network_code":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode reportAuthenticationCodeMissing#91efce48: field mobile_network_code: %w", err)
			}
			r.MobileNetworkCode = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetMobileNetworkCode returns value of MobileNetworkCode field.
func (r *ReportAuthenticationCodeMissingRequest) GetMobileNetworkCode() (value string) {
	if r == nil {
		return
	}
	return r.MobileNetworkCode
}

// ReportAuthenticationCodeMissing invokes method reportAuthenticationCodeMissing#91efce48 returning error if any.
func (c *Client) ReportAuthenticationCodeMissing(ctx context.Context, mobilenetworkcode string) error {
	var ok Ok

	request := &ReportAuthenticationCodeMissingRequest{
		MobileNetworkCode: mobilenetworkcode,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
