// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// ChannelsSetEmojiStickersRequest represents TL type `channels.setEmojiStickers#3cd930b7`.
// Set a custom emoji stickerset¹ for supergroups. Only usable after reaching at least
// the boost level »² specified in the group_emoji_stickers_level_min »³ config
// parameter.
//
// Links:
//  1. https://core.telegram.org/api/custom-emoji
//  2. https://core.telegram.org/api/boost
//  3. https://core.telegram.org/api/config#group-emoji-stickers-level-min
//
// See https://core.telegram.org/method/channels.setEmojiStickers for reference.
type ChannelsSetEmojiStickersRequest struct {
	// The supergroup
	Channel InputChannelClass
	// The custom emoji stickerset to associate to the supergroup
	Stickerset InputStickerSetClass
}

// ChannelsSetEmojiStickersRequestTypeID is TL type id of ChannelsSetEmojiStickersRequest.
const ChannelsSetEmojiStickersRequestTypeID = 0x3cd930b7

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

func (s *ChannelsSetEmojiStickersRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Channel == nil) {
		return false
	}
	if !(s.Stickerset == nil) {
		return false
	}

	return true
}

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

// FillFrom fills ChannelsSetEmojiStickersRequest from given interface.
func (s *ChannelsSetEmojiStickersRequest) FillFrom(from interface {
	GetChannel() (value InputChannelClass)
	GetStickerset() (value InputStickerSetClass)
}) {
	s.Channel = from.GetChannel()
	s.Stickerset = from.GetStickerset()
}

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

// TypeName returns name of type in TL schema.
func (*ChannelsSetEmojiStickersRequest) TypeName() string {
	return "channels.setEmojiStickers"
}

// TypeInfo returns info about TL type.
func (s *ChannelsSetEmojiStickersRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "channels.setEmojiStickers",
		ID:   ChannelsSetEmojiStickersRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Channel",
			SchemaName: "channel",
		},
		{
			Name:       "Stickerset",
			SchemaName: "stickerset",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *ChannelsSetEmojiStickersRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode channels.setEmojiStickers#3cd930b7 as nil")
	}
	b.PutID(ChannelsSetEmojiStickersRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *ChannelsSetEmojiStickersRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode channels.setEmojiStickers#3cd930b7 as nil")
	}
	if s.Channel == nil {
		return fmt.Errorf("unable to encode channels.setEmojiStickers#3cd930b7: field channel is nil")
	}
	if err := s.Channel.Encode(b); err != nil {
		return fmt.Errorf("unable to encode channels.setEmojiStickers#3cd930b7: field channel: %w", err)
	}
	if s.Stickerset == nil {
		return fmt.Errorf("unable to encode channels.setEmojiStickers#3cd930b7: field stickerset is nil")
	}
	if err := s.Stickerset.Encode(b); err != nil {
		return fmt.Errorf("unable to encode channels.setEmojiStickers#3cd930b7: field stickerset: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *ChannelsSetEmojiStickersRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode channels.setEmojiStickers#3cd930b7 to nil")
	}
	if err := b.ConsumeID(ChannelsSetEmojiStickersRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode channels.setEmojiStickers#3cd930b7: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *ChannelsSetEmojiStickersRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode channels.setEmojiStickers#3cd930b7 to nil")
	}
	{
		value, err := DecodeInputChannel(b)
		if err != nil {
			return fmt.Errorf("unable to decode channels.setEmojiStickers#3cd930b7: field channel: %w", err)
		}
		s.Channel = value
	}
	{
		value, err := DecodeInputStickerSet(b)
		if err != nil {
			return fmt.Errorf("unable to decode channels.setEmojiStickers#3cd930b7: field stickerset: %w", err)
		}
		s.Stickerset = value
	}
	return nil
}

// GetChannel returns value of Channel field.
func (s *ChannelsSetEmojiStickersRequest) GetChannel() (value InputChannelClass) {
	if s == nil {
		return
	}
	return s.Channel
}

// GetStickerset returns value of Stickerset field.
func (s *ChannelsSetEmojiStickersRequest) GetStickerset() (value InputStickerSetClass) {
	if s == nil {
		return
	}
	return s.Stickerset
}

// GetChannelAsNotEmpty returns mapped value of Channel field.
func (s *ChannelsSetEmojiStickersRequest) GetChannelAsNotEmpty() (NotEmptyInputChannel, bool) {
	return s.Channel.AsNotEmpty()
}

// ChannelsSetEmojiStickers invokes method channels.setEmojiStickers#3cd930b7 returning error if any.
// Set a custom emoji stickerset¹ for supergroups. Only usable after reaching at least
// the boost level »² specified in the group_emoji_stickers_level_min »³ config
// parameter.
//
// Links:
//  1. https://core.telegram.org/api/custom-emoji
//  2. https://core.telegram.org/api/boost
//  3. https://core.telegram.org/api/config#group-emoji-stickers-level-min
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//
// See https://core.telegram.org/method/channels.setEmojiStickers for reference.
func (c *Client) ChannelsSetEmojiStickers(ctx context.Context, request *ChannelsSetEmojiStickersRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
