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

// SetChatProfileAccentColorRequest represents TL type `setChatProfileAccentColor#4227ae7a`.
type SetChatProfileAccentColorRequest struct {
	// Chat identifier
	ChatID int64
	// Identifier of the accent color to use for profile; pass -1 if none. The chat must have
	// at least profileAccentColor.min_supergroup_chat_boost_level for supergroups
	ProfileAccentColorID int32
	// Identifier of a custom emoji to be shown on the chat's profile photo background; 0 if
	// none. Use chatBoostLevelFeatures.can_set_profile_background_custom_emoji to check
	// whether a custom emoji can be set
	ProfileBackgroundCustomEmojiID int64
}

// SetChatProfileAccentColorRequestTypeID is TL type id of SetChatProfileAccentColorRequest.
const SetChatProfileAccentColorRequestTypeID = 0x4227ae7a

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

func (s *SetChatProfileAccentColorRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.ProfileAccentColorID == 0) {
		return false
	}
	if !(s.ProfileBackgroundCustomEmojiID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetChatProfileAccentColorRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setChatProfileAccentColor",
		ID:   SetChatProfileAccentColorRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "ProfileAccentColorID",
			SchemaName: "profile_accent_color_id",
		},
		{
			Name:       "ProfileBackgroundCustomEmojiID",
			SchemaName: "profile_background_custom_emoji_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetChatProfileAccentColorRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatProfileAccentColor#4227ae7a as nil")
	}
	b.PutID(SetChatProfileAccentColorRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetChatProfileAccentColorRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatProfileAccentColor#4227ae7a as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutInt32(s.ProfileAccentColorID)
	b.PutLong(s.ProfileBackgroundCustomEmojiID)
	return nil
}

// Decode implements bin.Decoder.
func (s *SetChatProfileAccentColorRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setChatProfileAccentColor#4227ae7a to nil")
	}
	if err := b.ConsumeID(SetChatProfileAccentColorRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setChatProfileAccentColor#4227ae7a: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetChatProfileAccentColorRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setChatProfileAccentColor#4227ae7a to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setChatProfileAccentColor#4227ae7a: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode setChatProfileAccentColor#4227ae7a: field profile_accent_color_id: %w", err)
		}
		s.ProfileAccentColorID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode setChatProfileAccentColor#4227ae7a: field profile_background_custom_emoji_id: %w", err)
		}
		s.ProfileBackgroundCustomEmojiID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetChatProfileAccentColorRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatProfileAccentColor#4227ae7a as nil")
	}
	b.ObjStart()
	b.PutID("setChatProfileAccentColor")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("profile_accent_color_id")
	b.PutInt32(s.ProfileAccentColorID)
	b.Comma()
	b.FieldStart("profile_background_custom_emoji_id")
	b.PutLong(s.ProfileBackgroundCustomEmojiID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetChatProfileAccentColorRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setChatProfileAccentColor#4227ae7a to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setChatProfileAccentColor"); err != nil {
				return fmt.Errorf("unable to decode setChatProfileAccentColor#4227ae7a: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setChatProfileAccentColor#4227ae7a: field chat_id: %w", err)
			}
			s.ChatID = value
		case "profile_accent_color_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode setChatProfileAccentColor#4227ae7a: field profile_accent_color_id: %w", err)
			}
			s.ProfileAccentColorID = value
		case "profile_background_custom_emoji_id":
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode setChatProfileAccentColor#4227ae7a: field profile_background_custom_emoji_id: %w", err)
			}
			s.ProfileBackgroundCustomEmojiID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetProfileAccentColorID returns value of ProfileAccentColorID field.
func (s *SetChatProfileAccentColorRequest) GetProfileAccentColorID() (value int32) {
	if s == nil {
		return
	}
	return s.ProfileAccentColorID
}

// GetProfileBackgroundCustomEmojiID returns value of ProfileBackgroundCustomEmojiID field.
func (s *SetChatProfileAccentColorRequest) GetProfileBackgroundCustomEmojiID() (value int64) {
	if s == nil {
		return
	}
	return s.ProfileBackgroundCustomEmojiID
}

// SetChatProfileAccentColor invokes method setChatProfileAccentColor#4227ae7a returning error if any.
func (c *Client) SetChatProfileAccentColor(ctx context.Context, request *SetChatProfileAccentColorRequest) error {
	var ok Ok

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