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

// SetChatAccentColorRequest represents TL type `setChatAccentColor#349f57ca`.
type SetChatAccentColorRequest struct {
	// Chat identifier
	ChatID int64
	// Identifier of the accent color to use. The chat must have at least accentColor
	// min_channel_chat_boost_level boost level to pass the corresponding color
	AccentColorID int32
	// Identifier of a custom emoji to be shown on the reply header and link preview
	// background; 0 if none. Use chatBoostLevelFeatures.can_set_background_custom_emoji to
	// check whether a custom emoji can be set
	BackgroundCustomEmojiID int64
}

// SetChatAccentColorRequestTypeID is TL type id of SetChatAccentColorRequest.
const SetChatAccentColorRequestTypeID = 0x349f57ca

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

func (s *SetChatAccentColorRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.AccentColorID == 0) {
		return false
	}
	if !(s.BackgroundCustomEmojiID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetChatAccentColorRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setChatAccentColor",
		ID:   SetChatAccentColorRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "AccentColorID",
			SchemaName: "accent_color_id",
		},
		{
			Name:       "BackgroundCustomEmojiID",
			SchemaName: "background_custom_emoji_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetChatAccentColorRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatAccentColor#349f57ca as nil")
	}
	b.PutID(SetChatAccentColorRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetChatAccentColorRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatAccentColor#349f57ca as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutInt32(s.AccentColorID)
	b.PutLong(s.BackgroundCustomEmojiID)
	return nil
}

// Decode implements bin.Decoder.
func (s *SetChatAccentColorRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setChatAccentColor#349f57ca to nil")
	}
	if err := b.ConsumeID(SetChatAccentColorRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setChatAccentColor#349f57ca: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetChatAccentColorRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setChatAccentColor#349f57ca to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setChatAccentColor#349f57ca: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode setChatAccentColor#349f57ca: field accent_color_id: %w", err)
		}
		s.AccentColorID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode setChatAccentColor#349f57ca: field background_custom_emoji_id: %w", err)
		}
		s.BackgroundCustomEmojiID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetChatAccentColorRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatAccentColor#349f57ca as nil")
	}
	b.ObjStart()
	b.PutID("setChatAccentColor")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("accent_color_id")
	b.PutInt32(s.AccentColorID)
	b.Comma()
	b.FieldStart("background_custom_emoji_id")
	b.PutLong(s.BackgroundCustomEmojiID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetChatAccentColorRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setChatAccentColor#349f57ca to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setChatAccentColor"); err != nil {
				return fmt.Errorf("unable to decode setChatAccentColor#349f57ca: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setChatAccentColor#349f57ca: field chat_id: %w", err)
			}
			s.ChatID = value
		case "accent_color_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode setChatAccentColor#349f57ca: field accent_color_id: %w", err)
			}
			s.AccentColorID = value
		case "background_custom_emoji_id":
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode setChatAccentColor#349f57ca: field background_custom_emoji_id: %w", err)
			}
			s.BackgroundCustomEmojiID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (s *SetChatAccentColorRequest) GetChatID() (value int64) {
	if s == nil {
		return
	}
	return s.ChatID
}

// GetAccentColorID returns value of AccentColorID field.
func (s *SetChatAccentColorRequest) GetAccentColorID() (value int32) {
	if s == nil {
		return
	}
	return s.AccentColorID
}

// GetBackgroundCustomEmojiID returns value of BackgroundCustomEmojiID field.
func (s *SetChatAccentColorRequest) GetBackgroundCustomEmojiID() (value int64) {
	if s == nil {
		return
	}
	return s.BackgroundCustomEmojiID
}

// SetChatAccentColor invokes method setChatAccentColor#349f57ca returning error if any.
func (c *Client) SetChatAccentColor(ctx context.Context, request *SetChatAccentColorRequest) error {
	var ok Ok

	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
