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

// ProfileAccentColor represents TL type `profileAccentColor#213d8295`.
type ProfileAccentColor struct {
	// Profile accent color identifier
	ID int32
	// Accent colors expected to be used in light themes
	LightThemeColors ProfileAccentColors
	// Accent colors expected to be used in dark themes
	DarkThemeColors ProfileAccentColors
	// The minimum chat boost level required to use the color in a supergroup chat
	MinSupergroupChatBoostLevel int32
	// The minimum chat boost level required to use the color in a channel chat
	MinChannelChatBoostLevel int32
}

// ProfileAccentColorTypeID is TL type id of ProfileAccentColor.
const ProfileAccentColorTypeID = 0x213d8295

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

func (p *ProfileAccentColor) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.ID == 0) {
		return false
	}
	if !(p.LightThemeColors.Zero()) {
		return false
	}
	if !(p.DarkThemeColors.Zero()) {
		return false
	}
	if !(p.MinSupergroupChatBoostLevel == 0) {
		return false
	}
	if !(p.MinChannelChatBoostLevel == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *ProfileAccentColor) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "profileAccentColor",
		ID:   ProfileAccentColorTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "LightThemeColors",
			SchemaName: "light_theme_colors",
		},
		{
			Name:       "DarkThemeColors",
			SchemaName: "dark_theme_colors",
		},
		{
			Name:       "MinSupergroupChatBoostLevel",
			SchemaName: "min_supergroup_chat_boost_level",
		},
		{
			Name:       "MinChannelChatBoostLevel",
			SchemaName: "min_channel_chat_boost_level",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *ProfileAccentColor) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode profileAccentColor#213d8295 as nil")
	}
	b.PutID(ProfileAccentColorTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *ProfileAccentColor) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode profileAccentColor#213d8295 as nil")
	}
	b.PutInt32(p.ID)
	if err := p.LightThemeColors.Encode(b); err != nil {
		return fmt.Errorf("unable to encode profileAccentColor#213d8295: field light_theme_colors: %w", err)
	}
	if err := p.DarkThemeColors.Encode(b); err != nil {
		return fmt.Errorf("unable to encode profileAccentColor#213d8295: field dark_theme_colors: %w", err)
	}
	b.PutInt32(p.MinSupergroupChatBoostLevel)
	b.PutInt32(p.MinChannelChatBoostLevel)
	return nil
}

// Decode implements bin.Decoder.
func (p *ProfileAccentColor) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode profileAccentColor#213d8295 to nil")
	}
	if err := b.ConsumeID(ProfileAccentColorTypeID); err != nil {
		return fmt.Errorf("unable to decode profileAccentColor#213d8295: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *ProfileAccentColor) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode profileAccentColor#213d8295 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode profileAccentColor#213d8295: field id: %w", err)
		}
		p.ID = value
	}
	{
		if err := p.LightThemeColors.Decode(b); err != nil {
			return fmt.Errorf("unable to decode profileAccentColor#213d8295: field light_theme_colors: %w", err)
		}
	}
	{
		if err := p.DarkThemeColors.Decode(b); err != nil {
			return fmt.Errorf("unable to decode profileAccentColor#213d8295: field dark_theme_colors: %w", err)
		}
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode profileAccentColor#213d8295: field min_supergroup_chat_boost_level: %w", err)
		}
		p.MinSupergroupChatBoostLevel = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode profileAccentColor#213d8295: field min_channel_chat_boost_level: %w", err)
		}
		p.MinChannelChatBoostLevel = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *ProfileAccentColor) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode profileAccentColor#213d8295 as nil")
	}
	b.ObjStart()
	b.PutID("profileAccentColor")
	b.Comma()
	b.FieldStart("id")
	b.PutInt32(p.ID)
	b.Comma()
	b.FieldStart("light_theme_colors")
	if err := p.LightThemeColors.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode profileAccentColor#213d8295: field light_theme_colors: %w", err)
	}
	b.Comma()
	b.FieldStart("dark_theme_colors")
	if err := p.DarkThemeColors.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode profileAccentColor#213d8295: field dark_theme_colors: %w", err)
	}
	b.Comma()
	b.FieldStart("min_supergroup_chat_boost_level")
	b.PutInt32(p.MinSupergroupChatBoostLevel)
	b.Comma()
	b.FieldStart("min_channel_chat_boost_level")
	b.PutInt32(p.MinChannelChatBoostLevel)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *ProfileAccentColor) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode profileAccentColor#213d8295 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("profileAccentColor"); err != nil {
				return fmt.Errorf("unable to decode profileAccentColor#213d8295: %w", err)
			}
		case "id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode profileAccentColor#213d8295: field id: %w", err)
			}
			p.ID = value
		case "light_theme_colors":
			if err := p.LightThemeColors.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode profileAccentColor#213d8295: field light_theme_colors: %w", err)
			}
		case "dark_theme_colors":
			if err := p.DarkThemeColors.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode profileAccentColor#213d8295: field dark_theme_colors: %w", err)
			}
		case "min_supergroup_chat_boost_level":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode profileAccentColor#213d8295: field min_supergroup_chat_boost_level: %w", err)
			}
			p.MinSupergroupChatBoostLevel = value
		case "min_channel_chat_boost_level":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode profileAccentColor#213d8295: field min_channel_chat_boost_level: %w", err)
			}
			p.MinChannelChatBoostLevel = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetID returns value of ID field.
func (p *ProfileAccentColor) GetID() (value int32) {
	if p == nil {
		return
	}
	return p.ID
}

// GetLightThemeColors returns value of LightThemeColors field.
func (p *ProfileAccentColor) GetLightThemeColors() (value ProfileAccentColors) {
	if p == nil {
		return
	}
	return p.LightThemeColors
}

// GetDarkThemeColors returns value of DarkThemeColors field.
func (p *ProfileAccentColor) GetDarkThemeColors() (value ProfileAccentColors) {
	if p == nil {
		return
	}
	return p.DarkThemeColors
}

// GetMinSupergroupChatBoostLevel returns value of MinSupergroupChatBoostLevel field.
func (p *ProfileAccentColor) GetMinSupergroupChatBoostLevel() (value int32) {
	if p == nil {
		return
	}
	return p.MinSupergroupChatBoostLevel
}

// GetMinChannelChatBoostLevel returns value of MinChannelChatBoostLevel field.
func (p *ProfileAccentColor) GetMinChannelChatBoostLevel() (value int32) {
	if p == nil {
		return
	}
	return p.MinChannelChatBoostLevel
}
