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

// MessagesCheckURLAuthMatchCodeRequest represents TL type `messages.checkUrlAuthMatchCode#c9a47b0b`.
//
// See https://core.telegram.org/method/messages.checkUrlAuthMatchCode for reference.
type MessagesCheckURLAuthMatchCodeRequest struct {
	// URL field of MessagesCheckURLAuthMatchCodeRequest.
	URL string
	// MatchCode field of MessagesCheckURLAuthMatchCodeRequest.
	MatchCode string
}

// MessagesCheckURLAuthMatchCodeRequestTypeID is TL type id of MessagesCheckURLAuthMatchCodeRequest.
const MessagesCheckURLAuthMatchCodeRequestTypeID = 0xc9a47b0b

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

func (c *MessagesCheckURLAuthMatchCodeRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.URL == "") {
		return false
	}
	if !(c.MatchCode == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesCheckURLAuthMatchCodeRequest from given interface.
func (c *MessagesCheckURLAuthMatchCodeRequest) FillFrom(from interface {
	GetURL() (value string)
	GetMatchCode() (value string)
}) {
	c.URL = from.GetURL()
	c.MatchCode = from.GetMatchCode()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesCheckURLAuthMatchCodeRequest) TypeName() string {
	return "messages.checkUrlAuthMatchCode"
}

// TypeInfo returns info about TL type.
func (c *MessagesCheckURLAuthMatchCodeRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.checkUrlAuthMatchCode",
		ID:   MessagesCheckURLAuthMatchCodeRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "MatchCode",
			SchemaName: "match_code",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *MessagesCheckURLAuthMatchCodeRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode messages.checkUrlAuthMatchCode#c9a47b0b as nil")
	}
	b.PutID(MessagesCheckURLAuthMatchCodeRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *MessagesCheckURLAuthMatchCodeRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode messages.checkUrlAuthMatchCode#c9a47b0b as nil")
	}
	b.PutString(c.URL)
	b.PutString(c.MatchCode)
	return nil
}

// Decode implements bin.Decoder.
func (c *MessagesCheckURLAuthMatchCodeRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode messages.checkUrlAuthMatchCode#c9a47b0b to nil")
	}
	if err := b.ConsumeID(MessagesCheckURLAuthMatchCodeRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.checkUrlAuthMatchCode#c9a47b0b: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *MessagesCheckURLAuthMatchCodeRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode messages.checkUrlAuthMatchCode#c9a47b0b to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.checkUrlAuthMatchCode#c9a47b0b: field url: %w", err)
		}
		c.URL = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.checkUrlAuthMatchCode#c9a47b0b: field match_code: %w", err)
		}
		c.MatchCode = value
	}
	return nil
}

// GetURL returns value of URL field.
func (c *MessagesCheckURLAuthMatchCodeRequest) GetURL() (value string) {
	if c == nil {
		return
	}
	return c.URL
}

// GetMatchCode returns value of MatchCode field.
func (c *MessagesCheckURLAuthMatchCodeRequest) GetMatchCode() (value string) {
	if c == nil {
		return
	}
	return c.MatchCode
}

// MessagesCheckURLAuthMatchCode invokes method messages.checkUrlAuthMatchCode#c9a47b0b returning error if any.
//
// See https://core.telegram.org/method/messages.checkUrlAuthMatchCode for reference.
func (c *Client) MessagesCheckURLAuthMatchCode(ctx context.Context, request *MessagesCheckURLAuthMatchCodeRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
