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

// AttachmentMenuBotColor represents TL type `attachmentMenuBotColor#64235ebc`.
type AttachmentMenuBotColor struct {
	// Color in the RGB format for light themes
	LightColor int32
	// Color in the RGB format for dark themes
	DarkColor int32
}

// AttachmentMenuBotColorTypeID is TL type id of AttachmentMenuBotColor.
const AttachmentMenuBotColorTypeID = 0x64235ebc

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

func (a *AttachmentMenuBotColor) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.LightColor == 0) {
		return false
	}
	if !(a.DarkColor == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AttachmentMenuBotColor) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "attachmentMenuBotColor",
		ID:   AttachmentMenuBotColorTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "LightColor",
			SchemaName: "light_color",
		},
		{
			Name:       "DarkColor",
			SchemaName: "dark_color",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AttachmentMenuBotColor) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode attachmentMenuBotColor#64235ebc as nil")
	}
	b.PutID(AttachmentMenuBotColorTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AttachmentMenuBotColor) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode attachmentMenuBotColor#64235ebc as nil")
	}
	b.PutInt32(a.LightColor)
	b.PutInt32(a.DarkColor)
	return nil
}

// Decode implements bin.Decoder.
func (a *AttachmentMenuBotColor) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode attachmentMenuBotColor#64235ebc to nil")
	}
	if err := b.ConsumeID(AttachmentMenuBotColorTypeID); err != nil {
		return fmt.Errorf("unable to decode attachmentMenuBotColor#64235ebc: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AttachmentMenuBotColor) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode attachmentMenuBotColor#64235ebc to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode attachmentMenuBotColor#64235ebc: field light_color: %w", err)
		}
		a.LightColor = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode attachmentMenuBotColor#64235ebc: field dark_color: %w", err)
		}
		a.DarkColor = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AttachmentMenuBotColor) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode attachmentMenuBotColor#64235ebc as nil")
	}
	b.ObjStart()
	b.PutID("attachmentMenuBotColor")
	b.Comma()
	b.FieldStart("light_color")
	b.PutInt32(a.LightColor)
	b.Comma()
	b.FieldStart("dark_color")
	b.PutInt32(a.DarkColor)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AttachmentMenuBotColor) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode attachmentMenuBotColor#64235ebc to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("attachmentMenuBotColor"); err != nil {
				return fmt.Errorf("unable to decode attachmentMenuBotColor#64235ebc: %w", err)
			}
		case "light_color":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode attachmentMenuBotColor#64235ebc: field light_color: %w", err)
			}
			a.LightColor = value
		case "dark_color":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode attachmentMenuBotColor#64235ebc: field dark_color: %w", err)
			}
			a.DarkColor = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetLightColor returns value of LightColor field.
func (a *AttachmentMenuBotColor) GetLightColor() (value int32) {
	if a == nil {
		return
	}
	return a.LightColor
}

// GetDarkColor returns value of DarkColor field.
func (a *AttachmentMenuBotColor) GetDarkColor() (value int32) {
	if a == nil {
		return
	}
	return a.DarkColor
}
