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

// AcceptedGiftTypes represents TL type `acceptedGiftTypes#6a4e6014`.
type AcceptedGiftTypes struct {
	// True, if unlimited regular gifts are accepted
	UnlimitedGifts bool
	// True, if limited regular gifts are accepted
	LimitedGifts bool
	// True, if upgraded gifts and regular gifts that can be upgraded for free are accepted
	UpgradedGifts bool
	// True, if Telegram Premium subscription is accepted
	PremiumSubscription bool
}

// AcceptedGiftTypesTypeID is TL type id of AcceptedGiftTypes.
const AcceptedGiftTypesTypeID = 0x6a4e6014

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

func (a *AcceptedGiftTypes) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.UnlimitedGifts == false) {
		return false
	}
	if !(a.LimitedGifts == false) {
		return false
	}
	if !(a.UpgradedGifts == false) {
		return false
	}
	if !(a.PremiumSubscription == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AcceptedGiftTypes) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "acceptedGiftTypes",
		ID:   AcceptedGiftTypesTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UnlimitedGifts",
			SchemaName: "unlimited_gifts",
		},
		{
			Name:       "LimitedGifts",
			SchemaName: "limited_gifts",
		},
		{
			Name:       "UpgradedGifts",
			SchemaName: "upgraded_gifts",
		},
		{
			Name:       "PremiumSubscription",
			SchemaName: "premium_subscription",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AcceptedGiftTypes) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode acceptedGiftTypes#6a4e6014 as nil")
	}
	b.PutID(AcceptedGiftTypesTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AcceptedGiftTypes) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode acceptedGiftTypes#6a4e6014 as nil")
	}
	b.PutBool(a.UnlimitedGifts)
	b.PutBool(a.LimitedGifts)
	b.PutBool(a.UpgradedGifts)
	b.PutBool(a.PremiumSubscription)
	return nil
}

// Decode implements bin.Decoder.
func (a *AcceptedGiftTypes) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode acceptedGiftTypes#6a4e6014 to nil")
	}
	if err := b.ConsumeID(AcceptedGiftTypesTypeID); err != nil {
		return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AcceptedGiftTypes) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode acceptedGiftTypes#6a4e6014 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: field unlimited_gifts: %w", err)
		}
		a.UnlimitedGifts = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: field limited_gifts: %w", err)
		}
		a.LimitedGifts = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: field upgraded_gifts: %w", err)
		}
		a.UpgradedGifts = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: field premium_subscription: %w", err)
		}
		a.PremiumSubscription = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AcceptedGiftTypes) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode acceptedGiftTypes#6a4e6014 as nil")
	}
	b.ObjStart()
	b.PutID("acceptedGiftTypes")
	b.Comma()
	b.FieldStart("unlimited_gifts")
	b.PutBool(a.UnlimitedGifts)
	b.Comma()
	b.FieldStart("limited_gifts")
	b.PutBool(a.LimitedGifts)
	b.Comma()
	b.FieldStart("upgraded_gifts")
	b.PutBool(a.UpgradedGifts)
	b.Comma()
	b.FieldStart("premium_subscription")
	b.PutBool(a.PremiumSubscription)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AcceptedGiftTypes) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode acceptedGiftTypes#6a4e6014 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("acceptedGiftTypes"); err != nil {
				return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: %w", err)
			}
		case "unlimited_gifts":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: field unlimited_gifts: %w", err)
			}
			a.UnlimitedGifts = value
		case "limited_gifts":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: field limited_gifts: %w", err)
			}
			a.LimitedGifts = value
		case "upgraded_gifts":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: field upgraded_gifts: %w", err)
			}
			a.UpgradedGifts = value
		case "premium_subscription":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode acceptedGiftTypes#6a4e6014: field premium_subscription: %w", err)
			}
			a.PremiumSubscription = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetUnlimitedGifts returns value of UnlimitedGifts field.
func (a *AcceptedGiftTypes) GetUnlimitedGifts() (value bool) {
	if a == nil {
		return
	}
	return a.UnlimitedGifts
}

// GetLimitedGifts returns value of LimitedGifts field.
func (a *AcceptedGiftTypes) GetLimitedGifts() (value bool) {
	if a == nil {
		return
	}
	return a.LimitedGifts
}

// GetUpgradedGifts returns value of UpgradedGifts field.
func (a *AcceptedGiftTypes) GetUpgradedGifts() (value bool) {
	if a == nil {
		return
	}
	return a.UpgradedGifts
}

// GetPremiumSubscription returns value of PremiumSubscription field.
func (a *AcceptedGiftTypes) GetPremiumSubscription() (value bool) {
	if a == nil {
		return
	}
	return a.PremiumSubscription
}
