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

// SendPhoneNumberFirebaseSMSRequest represents TL type `sendPhoneNumberFirebaseSms#f9c7084`.
type SendPhoneNumberFirebaseSMSRequest struct {
	// Play Integrity API or SafetyNet Attestation API token for the Android application, or
	// secret from push notification for the iOS application
	Token string
}

// SendPhoneNumberFirebaseSMSRequestTypeID is TL type id of SendPhoneNumberFirebaseSMSRequest.
const SendPhoneNumberFirebaseSMSRequestTypeID = 0xf9c7084

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

func (s *SendPhoneNumberFirebaseSMSRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Token == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SendPhoneNumberFirebaseSMSRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "sendPhoneNumberFirebaseSms",
		ID:   SendPhoneNumberFirebaseSMSRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Token",
			SchemaName: "token",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SendPhoneNumberFirebaseSMSRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode sendPhoneNumberFirebaseSms#f9c7084 as nil")
	}
	b.PutID(SendPhoneNumberFirebaseSMSRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SendPhoneNumberFirebaseSMSRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode sendPhoneNumberFirebaseSms#f9c7084 as nil")
	}
	b.PutString(s.Token)
	return nil
}

// Decode implements bin.Decoder.
func (s *SendPhoneNumberFirebaseSMSRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode sendPhoneNumberFirebaseSms#f9c7084 to nil")
	}
	if err := b.ConsumeID(SendPhoneNumberFirebaseSMSRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode sendPhoneNumberFirebaseSms#f9c7084: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SendPhoneNumberFirebaseSMSRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode sendPhoneNumberFirebaseSms#f9c7084 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode sendPhoneNumberFirebaseSms#f9c7084: field token: %w", err)
		}
		s.Token = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SendPhoneNumberFirebaseSMSRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode sendPhoneNumberFirebaseSms#f9c7084 as nil")
	}
	b.ObjStart()
	b.PutID("sendPhoneNumberFirebaseSms")
	b.Comma()
	b.FieldStart("token")
	b.PutString(s.Token)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SendPhoneNumberFirebaseSMSRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode sendPhoneNumberFirebaseSms#f9c7084 to nil")
	}

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

// GetToken returns value of Token field.
func (s *SendPhoneNumberFirebaseSMSRequest) GetToken() (value string) {
	if s == nil {
		return
	}
	return s.Token
}

// SendPhoneNumberFirebaseSMS invokes method sendPhoneNumberFirebaseSms#f9c7084 returning error if any.
func (c *Client) SendPhoneNumberFirebaseSMS(ctx context.Context, token string) error {
	var ok Ok

	request := &SendPhoneNumberFirebaseSMSRequest{
		Token: token,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
