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

// BusinessFeaturePromotionAnimation represents TL type `businessFeaturePromotionAnimation#7a05680a`.
type BusinessFeaturePromotionAnimation struct {
	// Business feature
	Feature BusinessFeatureClass
	// Promotion animation for the feature
	Animation Animation
}

// BusinessFeaturePromotionAnimationTypeID is TL type id of BusinessFeaturePromotionAnimation.
const BusinessFeaturePromotionAnimationTypeID = 0x7a05680a

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

func (b *BusinessFeaturePromotionAnimation) Zero() bool {
	if b == nil {
		return true
	}
	if !(b.Feature == nil) {
		return false
	}
	if !(b.Animation.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (b *BusinessFeaturePromotionAnimation) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "businessFeaturePromotionAnimation",
		ID:   BusinessFeaturePromotionAnimationTypeID,
	}
	if b == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Feature",
			SchemaName: "feature",
		},
		{
			Name:       "Animation",
			SchemaName: "animation",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (b *BusinessFeaturePromotionAnimation) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode businessFeaturePromotionAnimation#7a05680a as nil")
	}
	buf.PutID(BusinessFeaturePromotionAnimationTypeID)
	return b.EncodeBare(buf)
}

// EncodeBare implements bin.BareEncoder.
func (b *BusinessFeaturePromotionAnimation) EncodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode businessFeaturePromotionAnimation#7a05680a as nil")
	}
	if b.Feature == nil {
		return fmt.Errorf("unable to encode businessFeaturePromotionAnimation#7a05680a: field feature is nil")
	}
	if err := b.Feature.Encode(buf); err != nil {
		return fmt.Errorf("unable to encode businessFeaturePromotionAnimation#7a05680a: field feature: %w", err)
	}
	if err := b.Animation.Encode(buf); err != nil {
		return fmt.Errorf("unable to encode businessFeaturePromotionAnimation#7a05680a: field animation: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (b *BusinessFeaturePromotionAnimation) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode businessFeaturePromotionAnimation#7a05680a to nil")
	}
	if err := buf.ConsumeID(BusinessFeaturePromotionAnimationTypeID); err != nil {
		return fmt.Errorf("unable to decode businessFeaturePromotionAnimation#7a05680a: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BusinessFeaturePromotionAnimation) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode businessFeaturePromotionAnimation#7a05680a to nil")
	}
	{
		value, err := DecodeBusinessFeature(buf)
		if err != nil {
			return fmt.Errorf("unable to decode businessFeaturePromotionAnimation#7a05680a: field feature: %w", err)
		}
		b.Feature = value
	}
	{
		if err := b.Animation.Decode(buf); err != nil {
			return fmt.Errorf("unable to decode businessFeaturePromotionAnimation#7a05680a: field animation: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (b *BusinessFeaturePromotionAnimation) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil {
		return fmt.Errorf("can't encode businessFeaturePromotionAnimation#7a05680a as nil")
	}
	buf.ObjStart()
	buf.PutID("businessFeaturePromotionAnimation")
	buf.Comma()
	buf.FieldStart("feature")
	if b.Feature == nil {
		return fmt.Errorf("unable to encode businessFeaturePromotionAnimation#7a05680a: field feature is nil")
	}
	if err := b.Feature.EncodeTDLibJSON(buf); err != nil {
		return fmt.Errorf("unable to encode businessFeaturePromotionAnimation#7a05680a: field feature: %w", err)
	}
	buf.Comma()
	buf.FieldStart("animation")
	if err := b.Animation.EncodeTDLibJSON(buf); err != nil {
		return fmt.Errorf("unable to encode businessFeaturePromotionAnimation#7a05680a: field animation: %w", err)
	}
	buf.Comma()
	buf.StripComma()
	buf.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (b *BusinessFeaturePromotionAnimation) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("can't decode businessFeaturePromotionAnimation#7a05680a to nil")
	}

	return buf.Obj(func(buf tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := buf.ConsumeID("businessFeaturePromotionAnimation"); err != nil {
				return fmt.Errorf("unable to decode businessFeaturePromotionAnimation#7a05680a: %w", err)
			}
		case "feature":
			value, err := DecodeTDLibJSONBusinessFeature(buf)
			if err != nil {
				return fmt.Errorf("unable to decode businessFeaturePromotionAnimation#7a05680a: field feature: %w", err)
			}
			b.Feature = value
		case "animation":
			if err := b.Animation.DecodeTDLibJSON(buf); err != nil {
				return fmt.Errorf("unable to decode businessFeaturePromotionAnimation#7a05680a: field animation: %w", err)
			}
		default:
			return buf.Skip()
		}
		return nil
	})
}

// GetFeature returns value of Feature field.
func (b *BusinessFeaturePromotionAnimation) GetFeature() (value BusinessFeatureClass) {
	if b == nil {
		return
	}
	return b.Feature
}

// GetAnimation returns value of Animation field.
func (b *BusinessFeaturePromotionAnimation) GetAnimation() (value Animation) {
	if b == nil {
		return
	}
	return b.Animation
}
