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

// GiftForResaleOrderPrice represents TL type `giftForResaleOrderPrice#51c31862`.
type GiftForResaleOrderPrice struct {
}

// GiftForResaleOrderPriceTypeID is TL type id of GiftForResaleOrderPrice.
const GiftForResaleOrderPriceTypeID = 0x51c31862

// construct implements constructor of GiftForResaleOrderClass.
func (g GiftForResaleOrderPrice) construct() GiftForResaleOrderClass { return &g }

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

	_ GiftForResaleOrderClass = &GiftForResaleOrderPrice{}
)

func (g *GiftForResaleOrderPrice) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GiftForResaleOrderPrice) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "giftForResaleOrderPrice",
		ID:   GiftForResaleOrderPriceTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *GiftForResaleOrderPrice) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderPrice#51c31862 as nil")
	}
	b.PutID(GiftForResaleOrderPriceTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GiftForResaleOrderPrice) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderPrice#51c31862 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GiftForResaleOrderPrice) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode giftForResaleOrderPrice#51c31862 to nil")
	}
	if err := b.ConsumeID(GiftForResaleOrderPriceTypeID); err != nil {
		return fmt.Errorf("unable to decode giftForResaleOrderPrice#51c31862: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GiftForResaleOrderPrice) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode giftForResaleOrderPrice#51c31862 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GiftForResaleOrderPrice) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderPrice#51c31862 as nil")
	}
	b.ObjStart()
	b.PutID("giftForResaleOrderPrice")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GiftForResaleOrderPrice) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode giftForResaleOrderPrice#51c31862 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("giftForResaleOrderPrice"); err != nil {
				return fmt.Errorf("unable to decode giftForResaleOrderPrice#51c31862: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GiftForResaleOrderPriceChangeDate represents TL type `giftForResaleOrderPriceChangeDate#9b0569ca`.
type GiftForResaleOrderPriceChangeDate struct {
}

// GiftForResaleOrderPriceChangeDateTypeID is TL type id of GiftForResaleOrderPriceChangeDate.
const GiftForResaleOrderPriceChangeDateTypeID = 0x9b0569ca

// construct implements constructor of GiftForResaleOrderClass.
func (g GiftForResaleOrderPriceChangeDate) construct() GiftForResaleOrderClass { return &g }

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

	_ GiftForResaleOrderClass = &GiftForResaleOrderPriceChangeDate{}
)

func (g *GiftForResaleOrderPriceChangeDate) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GiftForResaleOrderPriceChangeDate) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "giftForResaleOrderPriceChangeDate",
		ID:   GiftForResaleOrderPriceChangeDateTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *GiftForResaleOrderPriceChangeDate) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderPriceChangeDate#9b0569ca as nil")
	}
	b.PutID(GiftForResaleOrderPriceChangeDateTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GiftForResaleOrderPriceChangeDate) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderPriceChangeDate#9b0569ca as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GiftForResaleOrderPriceChangeDate) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode giftForResaleOrderPriceChangeDate#9b0569ca to nil")
	}
	if err := b.ConsumeID(GiftForResaleOrderPriceChangeDateTypeID); err != nil {
		return fmt.Errorf("unable to decode giftForResaleOrderPriceChangeDate#9b0569ca: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GiftForResaleOrderPriceChangeDate) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode giftForResaleOrderPriceChangeDate#9b0569ca to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GiftForResaleOrderPriceChangeDate) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderPriceChangeDate#9b0569ca as nil")
	}
	b.ObjStart()
	b.PutID("giftForResaleOrderPriceChangeDate")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GiftForResaleOrderPriceChangeDate) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode giftForResaleOrderPriceChangeDate#9b0569ca to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("giftForResaleOrderPriceChangeDate"); err != nil {
				return fmt.Errorf("unable to decode giftForResaleOrderPriceChangeDate#9b0569ca: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GiftForResaleOrderNumber represents TL type `giftForResaleOrderNumber#b271e900`.
type GiftForResaleOrderNumber struct {
}

// GiftForResaleOrderNumberTypeID is TL type id of GiftForResaleOrderNumber.
const GiftForResaleOrderNumberTypeID = 0xb271e900

// construct implements constructor of GiftForResaleOrderClass.
func (g GiftForResaleOrderNumber) construct() GiftForResaleOrderClass { return &g }

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

	_ GiftForResaleOrderClass = &GiftForResaleOrderNumber{}
)

func (g *GiftForResaleOrderNumber) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GiftForResaleOrderNumber) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "giftForResaleOrderNumber",
		ID:   GiftForResaleOrderNumberTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *GiftForResaleOrderNumber) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderNumber#b271e900 as nil")
	}
	b.PutID(GiftForResaleOrderNumberTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GiftForResaleOrderNumber) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderNumber#b271e900 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GiftForResaleOrderNumber) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode giftForResaleOrderNumber#b271e900 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GiftForResaleOrderNumber) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode giftForResaleOrderNumber#b271e900 as nil")
	}
	b.ObjStart()
	b.PutID("giftForResaleOrderNumber")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("giftForResaleOrderNumber"); err != nil {
				return fmt.Errorf("unable to decode giftForResaleOrderNumber#b271e900: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GiftForResaleOrderClassName is schema name of GiftForResaleOrderClass.
const GiftForResaleOrderClassName = "GiftForResaleOrder"

// GiftForResaleOrderClass represents GiftForResaleOrder generic type.
//
// Example:
//
//	g, err := tdapi.DecodeGiftForResaleOrder(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.GiftForResaleOrderPrice: // giftForResaleOrderPrice#51c31862
//	case *tdapi.GiftForResaleOrderPriceChangeDate: // giftForResaleOrderPriceChangeDate#9b0569ca
//	case *tdapi.GiftForResaleOrderNumber: // giftForResaleOrderNumber#b271e900
//	default: panic(v)
//	}
type GiftForResaleOrderClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() GiftForResaleOrderClass

	// 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

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeGiftForResaleOrder implements binary de-serialization for GiftForResaleOrderClass.
func DecodeGiftForResaleOrder(buf *bin.Buffer) (GiftForResaleOrderClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case GiftForResaleOrderPriceTypeID:
		// Decoding giftForResaleOrderPrice#51c31862.
		v := GiftForResaleOrderPrice{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GiftForResaleOrderClass: %w", err)
		}
		return &v, nil
	case GiftForResaleOrderPriceChangeDateTypeID:
		// Decoding giftForResaleOrderPriceChangeDate#9b0569ca.
		v := GiftForResaleOrderPriceChangeDate{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GiftForResaleOrderClass: %w", err)
		}
		return &v, nil
	case GiftForResaleOrderNumberTypeID:
		// Decoding giftForResaleOrderNumber#b271e900.
		v := GiftForResaleOrderNumber{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GiftForResaleOrderClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode GiftForResaleOrderClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONGiftForResaleOrder implements binary de-serialization for GiftForResaleOrderClass.
func DecodeTDLibJSONGiftForResaleOrder(buf tdjson.Decoder) (GiftForResaleOrderClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "giftForResaleOrderPrice":
		// Decoding giftForResaleOrderPrice#51c31862.
		v := GiftForResaleOrderPrice{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GiftForResaleOrderClass: %w", err)
		}
		return &v, nil
	case "giftForResaleOrderPriceChangeDate":
		// Decoding giftForResaleOrderPriceChangeDate#9b0569ca.
		v := GiftForResaleOrderPriceChangeDate{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GiftForResaleOrderClass: %w", err)
		}
		return &v, nil
	case "giftForResaleOrderNumber":
		// Decoding giftForResaleOrderNumber#b271e900.
		v := GiftForResaleOrderNumber{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode GiftForResaleOrderClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode GiftForResaleOrderClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// GiftForResaleOrder boxes the GiftForResaleOrderClass providing a helper.
type GiftForResaleOrderBox struct {
	GiftForResaleOrder GiftForResaleOrderClass
}

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

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

// DecodeTDLibJSON implements bin.Decoder for GiftForResaleOrderBox.
func (b *GiftForResaleOrderBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode GiftForResaleOrderBox to nil")
	}
	v, err := DecodeTDLibJSONGiftForResaleOrder(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.GiftForResaleOrder = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for GiftForResaleOrderBox.
func (b *GiftForResaleOrderBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.GiftForResaleOrder == nil {
		return fmt.Errorf("unable to encode GiftForResaleOrderClass as nil")
	}
	return b.GiftForResaleOrder.EncodeTDLibJSON(buf)
}
