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

// GetPaymentReceiptRequest represents TL type `getPaymentReceipt#3c6cb956`.
type GetPaymentReceiptRequest struct {
	// Chat identifier of the messagePaymentSuccessful message
	ChatID int64
	// Message identifier
	MessageID int64
}

// GetPaymentReceiptRequestTypeID is TL type id of GetPaymentReceiptRequest.
const GetPaymentReceiptRequestTypeID = 0x3c6cb956

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

func (g *GetPaymentReceiptRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.ChatID == 0) {
		return false
	}
	if !(g.MessageID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetPaymentReceiptRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getPaymentReceipt",
		ID:   GetPaymentReceiptRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageID",
			SchemaName: "message_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetPaymentReceiptRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPaymentReceipt#3c6cb956 as nil")
	}
	b.PutID(GetPaymentReceiptRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetPaymentReceiptRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPaymentReceipt#3c6cb956 as nil")
	}
	b.PutInt53(g.ChatID)
	b.PutInt53(g.MessageID)
	return nil
}

// Decode implements bin.Decoder.
func (g *GetPaymentReceiptRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getPaymentReceipt#3c6cb956 to nil")
	}
	if err := b.ConsumeID(GetPaymentReceiptRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode getPaymentReceipt#3c6cb956: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GetPaymentReceiptRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getPaymentReceipt#3c6cb956 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode getPaymentReceipt#3c6cb956: field chat_id: %w", err)
		}
		g.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode getPaymentReceipt#3c6cb956: field message_id: %w", err)
		}
		g.MessageID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetPaymentReceiptRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getPaymentReceipt#3c6cb956 as nil")
	}
	b.ObjStart()
	b.PutID("getPaymentReceipt")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(g.ChatID)
	b.Comma()
	b.FieldStart("message_id")
	b.PutInt53(g.MessageID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetPaymentReceiptRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getPaymentReceipt#3c6cb956 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getPaymentReceipt"); err != nil {
				return fmt.Errorf("unable to decode getPaymentReceipt#3c6cb956: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode getPaymentReceipt#3c6cb956: field chat_id: %w", err)
			}
			g.ChatID = value
		case "message_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode getPaymentReceipt#3c6cb956: field message_id: %w", err)
			}
			g.MessageID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (g *GetPaymentReceiptRequest) GetChatID() (value int64) {
	if g == nil {
		return
	}
	return g.ChatID
}

// GetMessageID returns value of MessageID field.
func (g *GetPaymentReceiptRequest) GetMessageID() (value int64) {
	if g == nil {
		return
	}
	return g.MessageID
}

// GetPaymentReceipt invokes method getPaymentReceipt#3c6cb956 returning error if any.
func (c *Client) GetPaymentReceipt(ctx context.Context, request *GetPaymentReceiptRequest) (*PaymentReceipt, error) {
	var result PaymentReceipt

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