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

// SetProfileAccentColorRequest represents TL type `setProfileAccentColor#899bc168`.
type SetProfileAccentColorRequest struct {
	// Identifier of the accent color to use for profile; pass -1 if none
	ProfileAccentColorID int32
	// Identifier of a custom emoji to be shown on the user's profile photo background; 0 if
	// none
	ProfileBackgroundCustomEmojiID int64
}

// SetProfileAccentColorRequestTypeID is TL type id of SetProfileAccentColorRequest.
const SetProfileAccentColorRequestTypeID = 0x899bc168

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (s *SetProfileAccentColorRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setProfileAccentColor#899bc168 as nil")
	}
	b.PutID(SetProfileAccentColorRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetProfileAccentColorRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setProfileAccentColor#899bc168 as nil")
	}
	b.PutInt32(s.ProfileAccentColorID)
	b.PutLong(s.ProfileBackgroundCustomEmojiID)
	return nil
}

// Decode implements bin.Decoder.
func (s *SetProfileAccentColorRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setProfileAccentColor#899bc168 to nil")
	}
	if err := b.ConsumeID(SetProfileAccentColorRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setProfileAccentColor#899bc168: %w", err)
	}
	return s.DecodeBare(b)
}

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

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetProfileAccentColorRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setProfileAccentColor#899bc168 as nil")
	}
	b.ObjStart()
	b.PutID("setProfileAccentColor")
	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 *SetProfileAccentColorRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setProfileAccentColor#899bc168 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setProfileAccentColor"); err != nil {
				return fmt.Errorf("unable to decode setProfileAccentColor#899bc168: %w", err)
			}
		case "profile_accent_color_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode setProfileAccentColor#899bc168: 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 setProfileAccentColor#899bc168: field profile_background_custom_emoji_id: %w", err)
			}
			s.ProfileBackgroundCustomEmojiID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

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

// SetProfileAccentColor invokes method setProfileAccentColor#899bc168 returning error if any.
func (c *Client) SetProfileAccentColor(ctx context.Context, request *SetProfileAccentColorRequest) error {
	var ok Ok

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