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

// UpgradedGiftBackdropColors represents TL type `upgradedGiftBackdropColors#4081c9`.
type UpgradedGiftBackdropColors struct {
	// A color in the center of the backdrop in the RGB format
	CenterColor int32
	// A color on the edges of the backdrop in the RGB format
	EdgeColor int32
	// A color to be applied for the symbol in the RGB format
	SymbolColor int32
	// A color for the text on the backdrop in the RGB format
	TextColor int32
}

// UpgradedGiftBackdropColorsTypeID is TL type id of UpgradedGiftBackdropColors.
const UpgradedGiftBackdropColorsTypeID = 0x4081c9

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

func (u *UpgradedGiftBackdropColors) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.CenterColor == 0) {
		return false
	}
	if !(u.EdgeColor == 0) {
		return false
	}
	if !(u.SymbolColor == 0) {
		return false
	}
	if !(u.TextColor == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UpgradedGiftBackdropColors) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "upgradedGiftBackdropColors",
		ID:   UpgradedGiftBackdropColorsTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "CenterColor",
			SchemaName: "center_color",
		},
		{
			Name:       "EdgeColor",
			SchemaName: "edge_color",
		},
		{
			Name:       "SymbolColor",
			SchemaName: "symbol_color",
		},
		{
			Name:       "TextColor",
			SchemaName: "text_color",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *UpgradedGiftBackdropColors) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode upgradedGiftBackdropColors#4081c9 as nil")
	}
	b.PutID(UpgradedGiftBackdropColorsTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UpgradedGiftBackdropColors) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode upgradedGiftBackdropColors#4081c9 as nil")
	}
	b.PutInt32(u.CenterColor)
	b.PutInt32(u.EdgeColor)
	b.PutInt32(u.SymbolColor)
	b.PutInt32(u.TextColor)
	return nil
}

// Decode implements bin.Decoder.
func (u *UpgradedGiftBackdropColors) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode upgradedGiftBackdropColors#4081c9 to nil")
	}
	if err := b.ConsumeID(UpgradedGiftBackdropColorsTypeID); err != nil {
		return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UpgradedGiftBackdropColors) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode upgradedGiftBackdropColors#4081c9 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: field center_color: %w", err)
		}
		u.CenterColor = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: field edge_color: %w", err)
		}
		u.EdgeColor = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: field symbol_color: %w", err)
		}
		u.SymbolColor = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: field text_color: %w", err)
		}
		u.TextColor = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UpgradedGiftBackdropColors) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode upgradedGiftBackdropColors#4081c9 as nil")
	}
	b.ObjStart()
	b.PutID("upgradedGiftBackdropColors")
	b.Comma()
	b.FieldStart("center_color")
	b.PutInt32(u.CenterColor)
	b.Comma()
	b.FieldStart("edge_color")
	b.PutInt32(u.EdgeColor)
	b.Comma()
	b.FieldStart("symbol_color")
	b.PutInt32(u.SymbolColor)
	b.Comma()
	b.FieldStart("text_color")
	b.PutInt32(u.TextColor)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UpgradedGiftBackdropColors) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode upgradedGiftBackdropColors#4081c9 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("upgradedGiftBackdropColors"); err != nil {
				return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: %w", err)
			}
		case "center_color":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: field center_color: %w", err)
			}
			u.CenterColor = value
		case "edge_color":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: field edge_color: %w", err)
			}
			u.EdgeColor = value
		case "symbol_color":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: field symbol_color: %w", err)
			}
			u.SymbolColor = value
		case "text_color":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode upgradedGiftBackdropColors#4081c9: field text_color: %w", err)
			}
			u.TextColor = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetCenterColor returns value of CenterColor field.
func (u *UpgradedGiftBackdropColors) GetCenterColor() (value int32) {
	if u == nil {
		return
	}
	return u.CenterColor
}

// GetEdgeColor returns value of EdgeColor field.
func (u *UpgradedGiftBackdropColors) GetEdgeColor() (value int32) {
	if u == nil {
		return
	}
	return u.EdgeColor
}

// GetSymbolColor returns value of SymbolColor field.
func (u *UpgradedGiftBackdropColors) GetSymbolColor() (value int32) {
	if u == nil {
		return
	}
	return u.SymbolColor
}

// GetTextColor returns value of TextColor field.
func (u *UpgradedGiftBackdropColors) GetTextColor() (value int32) {
	if u == nil {
		return
	}
	return u.TextColor
}
