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

// ReportPhoneNumberCodeMissingRequest represents TL type `reportPhoneNumberCodeMissing#caa4b553`.
type ReportPhoneNumberCodeMissingRequest struct {
	// Current mobile network code
	MobileNetworkCode string
}

// ReportPhoneNumberCodeMissingRequestTypeID is TL type id of ReportPhoneNumberCodeMissingRequest.
const ReportPhoneNumberCodeMissingRequestTypeID = 0xcaa4b553

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *ReportPhoneNumberCodeMissingRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "reportPhoneNumberCodeMissing",
		ID:   ReportPhoneNumberCodeMissingRequestTypeID,
	}
	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 *ReportPhoneNumberCodeMissingRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reportPhoneNumberCodeMissing#caa4b553 as nil")
	}
	b.PutID(ReportPhoneNumberCodeMissingRequestTypeID)
	return r.EncodeBare(b)
}

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

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

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

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReportPhoneNumberCodeMissingRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode reportPhoneNumberCodeMissing#caa4b553 as nil")
	}
	b.ObjStart()
	b.PutID("reportPhoneNumberCodeMissing")
	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 *ReportPhoneNumberCodeMissingRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode reportPhoneNumberCodeMissing#caa4b553 to nil")
	}

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

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

// ReportPhoneNumberCodeMissing invokes method reportPhoneNumberCodeMissing#caa4b553 returning error if any.
func (c *Client) ReportPhoneNumberCodeMissing(ctx context.Context, mobilenetworkcode string) error {
	var ok Ok

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