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

// PaymentsCheckCanSendGiftResultOk represents TL type `payments.checkCanSendGiftResultOk#374fa7ad`.
// The specified gift can be sent.
//
// See https://core.telegram.org/constructor/payments.checkCanSendGiftResultOk for reference.
type PaymentsCheckCanSendGiftResultOk struct {
}

// PaymentsCheckCanSendGiftResultOkTypeID is TL type id of PaymentsCheckCanSendGiftResultOk.
const PaymentsCheckCanSendGiftResultOkTypeID = 0x374fa7ad

// construct implements constructor of PaymentsCheckCanSendGiftResultClass.
func (c PaymentsCheckCanSendGiftResultOk) construct() PaymentsCheckCanSendGiftResultClass { return &c }

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

	_ PaymentsCheckCanSendGiftResultClass = &PaymentsCheckCanSendGiftResultOk{}
)

func (c *PaymentsCheckCanSendGiftResultOk) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*PaymentsCheckCanSendGiftResultOk) TypeName() string {
	return "payments.checkCanSendGiftResultOk"
}

// TypeInfo returns info about TL type.
func (c *PaymentsCheckCanSendGiftResultOk) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.checkCanSendGiftResultOk",
		ID:   PaymentsCheckCanSendGiftResultOkTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (c *PaymentsCheckCanSendGiftResultOk) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode payments.checkCanSendGiftResultOk#374fa7ad as nil")
	}
	b.PutID(PaymentsCheckCanSendGiftResultOkTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *PaymentsCheckCanSendGiftResultOk) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode payments.checkCanSendGiftResultOk#374fa7ad as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *PaymentsCheckCanSendGiftResultOk) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode payments.checkCanSendGiftResultOk#374fa7ad to nil")
	}
	if err := b.ConsumeID(PaymentsCheckCanSendGiftResultOkTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.checkCanSendGiftResultOk#374fa7ad: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *PaymentsCheckCanSendGiftResultOk) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode payments.checkCanSendGiftResultOk#374fa7ad to nil")
	}
	return nil
}

// PaymentsCheckCanSendGiftResultFail represents TL type `payments.checkCanSendGiftResultFail#d5e58274`.
// The specified gift cannot be sent yet for the specified reason.
//
// See https://core.telegram.org/constructor/payments.checkCanSendGiftResultFail for reference.
type PaymentsCheckCanSendGiftResultFail struct {
	// The reason why it can't be sent yet.
	Reason TextWithEntities
}

// PaymentsCheckCanSendGiftResultFailTypeID is TL type id of PaymentsCheckCanSendGiftResultFail.
const PaymentsCheckCanSendGiftResultFailTypeID = 0xd5e58274

// construct implements constructor of PaymentsCheckCanSendGiftResultClass.
func (c PaymentsCheckCanSendGiftResultFail) construct() PaymentsCheckCanSendGiftResultClass {
	return &c
}

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

	_ PaymentsCheckCanSendGiftResultClass = &PaymentsCheckCanSendGiftResultFail{}
)

func (c *PaymentsCheckCanSendGiftResultFail) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.Reason.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsCheckCanSendGiftResultFail from given interface.
func (c *PaymentsCheckCanSendGiftResultFail) FillFrom(from interface {
	GetReason() (value TextWithEntities)
}) {
	c.Reason = from.GetReason()
}

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

// TypeName returns name of type in TL schema.
func (*PaymentsCheckCanSendGiftResultFail) TypeName() string {
	return "payments.checkCanSendGiftResultFail"
}

// TypeInfo returns info about TL type.
func (c *PaymentsCheckCanSendGiftResultFail) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.checkCanSendGiftResultFail",
		ID:   PaymentsCheckCanSendGiftResultFailTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Reason",
			SchemaName: "reason",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *PaymentsCheckCanSendGiftResultFail) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode payments.checkCanSendGiftResultFail#d5e58274 as nil")
	}
	b.PutID(PaymentsCheckCanSendGiftResultFailTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *PaymentsCheckCanSendGiftResultFail) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode payments.checkCanSendGiftResultFail#d5e58274 as nil")
	}
	if err := c.Reason.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.checkCanSendGiftResultFail#d5e58274: field reason: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *PaymentsCheckCanSendGiftResultFail) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode payments.checkCanSendGiftResultFail#d5e58274 to nil")
	}
	if err := b.ConsumeID(PaymentsCheckCanSendGiftResultFailTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.checkCanSendGiftResultFail#d5e58274: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *PaymentsCheckCanSendGiftResultFail) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode payments.checkCanSendGiftResultFail#d5e58274 to nil")
	}
	{
		if err := c.Reason.Decode(b); err != nil {
			return fmt.Errorf("unable to decode payments.checkCanSendGiftResultFail#d5e58274: field reason: %w", err)
		}
	}
	return nil
}

// GetReason returns value of Reason field.
func (c *PaymentsCheckCanSendGiftResultFail) GetReason() (value TextWithEntities) {
	if c == nil {
		return
	}
	return c.Reason
}

// PaymentsCheckCanSendGiftResultClassName is schema name of PaymentsCheckCanSendGiftResultClass.
const PaymentsCheckCanSendGiftResultClassName = "payments.CheckCanSendGiftResult"

// PaymentsCheckCanSendGiftResultClass represents payments.CheckCanSendGiftResult generic type.
//
// See https://core.telegram.org/type/payments.CheckCanSendGiftResult for reference.
//
// Example:
//
//	g, err := tg.DecodePaymentsCheckCanSendGiftResult(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.PaymentsCheckCanSendGiftResultOk: // payments.checkCanSendGiftResultOk#374fa7ad
//	case *tg.PaymentsCheckCanSendGiftResultFail: // payments.checkCanSendGiftResultFail#d5e58274
//	default: panic(v)
//	}
type PaymentsCheckCanSendGiftResultClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PaymentsCheckCanSendGiftResultClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool
}

// DecodePaymentsCheckCanSendGiftResult implements binary de-serialization for PaymentsCheckCanSendGiftResultClass.
func DecodePaymentsCheckCanSendGiftResult(buf *bin.Buffer) (PaymentsCheckCanSendGiftResultClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case PaymentsCheckCanSendGiftResultOkTypeID:
		// Decoding payments.checkCanSendGiftResultOk#374fa7ad.
		v := PaymentsCheckCanSendGiftResultOk{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PaymentsCheckCanSendGiftResultClass: %w", err)
		}
		return &v, nil
	case PaymentsCheckCanSendGiftResultFailTypeID:
		// Decoding payments.checkCanSendGiftResultFail#d5e58274.
		v := PaymentsCheckCanSendGiftResultFail{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PaymentsCheckCanSendGiftResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PaymentsCheckCanSendGiftResultClass: %w", bin.NewUnexpectedID(id))
	}
}

// PaymentsCheckCanSendGiftResult boxes the PaymentsCheckCanSendGiftResultClass providing a helper.
type PaymentsCheckCanSendGiftResultBox struct {
	CheckCanSendGiftResult PaymentsCheckCanSendGiftResultClass
}

// Decode implements bin.Decoder for PaymentsCheckCanSendGiftResultBox.
func (b *PaymentsCheckCanSendGiftResultBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode PaymentsCheckCanSendGiftResultBox to nil")
	}
	v, err := DecodePaymentsCheckCanSendGiftResult(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.CheckCanSendGiftResult = v
	return nil
}

// Encode implements bin.Encode for PaymentsCheckCanSendGiftResultBox.
func (b *PaymentsCheckCanSendGiftResultBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.CheckCanSendGiftResult == nil {
		return fmt.Errorf("unable to encode PaymentsCheckCanSendGiftResultClass as nil")
	}
	return b.CheckCanSendGiftResult.Encode(buf)
}
