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

// AuthCheckPaidAuthRequest represents TL type `auth.checkPaidAuth#56e59f9c`.
//
// See https://core.telegram.org/method/auth.checkPaidAuth for reference.
type AuthCheckPaidAuthRequest struct {
	// PhoneNumber field of AuthCheckPaidAuthRequest.
	PhoneNumber string
	// PhoneCodeHash field of AuthCheckPaidAuthRequest.
	PhoneCodeHash string
	// FormID field of AuthCheckPaidAuthRequest.
	FormID int64
}

// AuthCheckPaidAuthRequestTypeID is TL type id of AuthCheckPaidAuthRequest.
const AuthCheckPaidAuthRequestTypeID = 0x56e59f9c

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

func (c *AuthCheckPaidAuthRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.PhoneNumber == "") {
		return false
	}
	if !(c.PhoneCodeHash == "") {
		return false
	}
	if !(c.FormID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AuthCheckPaidAuthRequest from given interface.
func (c *AuthCheckPaidAuthRequest) FillFrom(from interface {
	GetPhoneNumber() (value string)
	GetPhoneCodeHash() (value string)
	GetFormID() (value int64)
}) {
	c.PhoneNumber = from.GetPhoneNumber()
	c.PhoneCodeHash = from.GetPhoneCodeHash()
	c.FormID = from.GetFormID()
}

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

// TypeName returns name of type in TL schema.
func (*AuthCheckPaidAuthRequest) TypeName() string {
	return "auth.checkPaidAuth"
}

// TypeInfo returns info about TL type.
func (c *AuthCheckPaidAuthRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.checkPaidAuth",
		ID:   AuthCheckPaidAuthRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "PhoneNumber",
			SchemaName: "phone_number",
		},
		{
			Name:       "PhoneCodeHash",
			SchemaName: "phone_code_hash",
		},
		{
			Name:       "FormID",
			SchemaName: "form_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *AuthCheckPaidAuthRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode auth.checkPaidAuth#56e59f9c as nil")
	}
	b.PutID(AuthCheckPaidAuthRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *AuthCheckPaidAuthRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode auth.checkPaidAuth#56e59f9c as nil")
	}
	b.PutString(c.PhoneNumber)
	b.PutString(c.PhoneCodeHash)
	b.PutLong(c.FormID)
	return nil
}

// Decode implements bin.Decoder.
func (c *AuthCheckPaidAuthRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode auth.checkPaidAuth#56e59f9c to nil")
	}
	if err := b.ConsumeID(AuthCheckPaidAuthRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.checkPaidAuth#56e59f9c: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *AuthCheckPaidAuthRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode auth.checkPaidAuth#56e59f9c to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.checkPaidAuth#56e59f9c: field phone_number: %w", err)
		}
		c.PhoneNumber = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.checkPaidAuth#56e59f9c: field phone_code_hash: %w", err)
		}
		c.PhoneCodeHash = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode auth.checkPaidAuth#56e59f9c: field form_id: %w", err)
		}
		c.FormID = value
	}
	return nil
}

// GetPhoneNumber returns value of PhoneNumber field.
func (c *AuthCheckPaidAuthRequest) GetPhoneNumber() (value string) {
	if c == nil {
		return
	}
	return c.PhoneNumber
}

// GetPhoneCodeHash returns value of PhoneCodeHash field.
func (c *AuthCheckPaidAuthRequest) GetPhoneCodeHash() (value string) {
	if c == nil {
		return
	}
	return c.PhoneCodeHash
}

// GetFormID returns value of FormID field.
func (c *AuthCheckPaidAuthRequest) GetFormID() (value int64) {
	if c == nil {
		return
	}
	return c.FormID
}

// AuthCheckPaidAuth invokes method auth.checkPaidAuth#56e59f9c returning error if any.
//
// See https://core.telegram.org/method/auth.checkPaidAuth for reference.
func (c *Client) AuthCheckPaidAuth(ctx context.Context, request *AuthCheckPaidAuthRequest) (AuthSentCodeClass, error) {
	var result AuthSentCodeBox

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