// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// InvokeWithGooglePlayIntegrityRequest represents TL type `invokeWithGooglePlayIntegrity#1df92984`.
// Official clients only, invoke with Google Play Integrity token.
//
// See https://core.telegram.org/constructor/invokeWithGooglePlayIntegrity for reference.
type InvokeWithGooglePlayIntegrityRequest struct {
	// Nonce.
	Nonce string
	// Token.
	Token string
	// Query.
	Query bin.Object
}

// InvokeWithGooglePlayIntegrityRequestTypeID is TL type id of InvokeWithGooglePlayIntegrityRequest.
const InvokeWithGooglePlayIntegrityRequestTypeID = 0x1df92984

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

func (i *InvokeWithGooglePlayIntegrityRequest) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.Nonce == "") {
		return false
	}
	if !(i.Token == "") {
		return false
	}
	if !(i.Query == nil) {
		return false
	}

	return true
}

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

// FillFrom fills InvokeWithGooglePlayIntegrityRequest from given interface.
func (i *InvokeWithGooglePlayIntegrityRequest) FillFrom(from interface {
	GetNonce() (value string)
	GetToken() (value string)
	GetQuery() (value bin.Object)
}) {
	i.Nonce = from.GetNonce()
	i.Token = from.GetToken()
	i.Query = from.GetQuery()
}

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

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

// TypeInfo returns info about TL type.
func (i *InvokeWithGooglePlayIntegrityRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "invokeWithGooglePlayIntegrity",
		ID:   InvokeWithGooglePlayIntegrityRequestTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Nonce",
			SchemaName: "nonce",
		},
		{
			Name:       "Token",
			SchemaName: "token",
		},
		{
			Name:       "Query",
			SchemaName: "query",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InvokeWithGooglePlayIntegrityRequest) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode invokeWithGooglePlayIntegrity#1df92984 as nil")
	}
	b.PutID(InvokeWithGooglePlayIntegrityRequestTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InvokeWithGooglePlayIntegrityRequest) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode invokeWithGooglePlayIntegrity#1df92984 as nil")
	}
	b.PutString(i.Nonce)
	b.PutString(i.Token)
	if err := i.Query.Encode(b); err != nil {
		return fmt.Errorf("unable to encode invokeWithGooglePlayIntegrity#1df92984: field query: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (i *InvokeWithGooglePlayIntegrityRequest) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode invokeWithGooglePlayIntegrity#1df92984 to nil")
	}
	if err := b.ConsumeID(InvokeWithGooglePlayIntegrityRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode invokeWithGooglePlayIntegrity#1df92984: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InvokeWithGooglePlayIntegrityRequest) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode invokeWithGooglePlayIntegrity#1df92984 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode invokeWithGooglePlayIntegrity#1df92984: field nonce: %w", err)
		}
		i.Nonce = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode invokeWithGooglePlayIntegrity#1df92984: field token: %w", err)
		}
		i.Token = value
	}
	{
		if err := i.Query.Decode(b); err != nil {
			return fmt.Errorf("unable to decode invokeWithGooglePlayIntegrity#1df92984: field query: %w", err)
		}
	}
	return nil
}

// GetNonce returns value of Nonce field.
func (i *InvokeWithGooglePlayIntegrityRequest) GetNonce() (value string) {
	if i == nil {
		return
	}
	return i.Nonce
}

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

// GetQuery returns value of Query field.
func (i *InvokeWithGooglePlayIntegrityRequest) GetQuery() (value bin.Object) {
	if i == nil {
		return
	}
	return i.Query
}
