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

// ChannelsSetBoostsToUnblockRestrictionsRequest represents TL type `channels.setBoostsToUnblockRestrictions#ad399cee`.
// Admins with ban_users admin rights »¹ may allow users that apply a certain number of
// booosts »² to the group to bypass slow mode »³ and other »⁴ supergroup
// restrictions, see here »⁵ for more info.
//
// Links:
//  1. https://core.telegram.org/constructor/chatAdminRights
//  2. https://core.telegram.org/api/boost
//  3. https://core.telegram.org/method/channels.toggleSlowMode
//  4. https://core.telegram.org/api/rights#default-rights
//  5. https://core.telegram.org/api/boost#bypass-slowmode-and-chat-restrictions
//
// See https://core.telegram.org/method/channels.setBoostsToUnblockRestrictions for reference.
type ChannelsSetBoostsToUnblockRestrictionsRequest struct {
	// The supergroup.
	Channel InputChannelClass
	// The number of required boosts (1-8, 0 to disable).
	Boosts int
}

// ChannelsSetBoostsToUnblockRestrictionsRequestTypeID is TL type id of ChannelsSetBoostsToUnblockRestrictionsRequest.
const ChannelsSetBoostsToUnblockRestrictionsRequestTypeID = 0xad399cee

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

func (s *ChannelsSetBoostsToUnblockRestrictionsRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Channel == nil) {
		return false
	}
	if !(s.Boosts == 0) {
		return false
	}

	return true
}

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

// FillFrom fills ChannelsSetBoostsToUnblockRestrictionsRequest from given interface.
func (s *ChannelsSetBoostsToUnblockRestrictionsRequest) FillFrom(from interface {
	GetChannel() (value InputChannelClass)
	GetBoosts() (value int)
}) {
	s.Channel = from.GetChannel()
	s.Boosts = from.GetBoosts()
}

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

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

// TypeInfo returns info about TL type.
func (s *ChannelsSetBoostsToUnblockRestrictionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "channels.setBoostsToUnblockRestrictions",
		ID:   ChannelsSetBoostsToUnblockRestrictionsRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Channel",
			SchemaName: "channel",
		},
		{
			Name:       "Boosts",
			SchemaName: "boosts",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *ChannelsSetBoostsToUnblockRestrictionsRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode channels.setBoostsToUnblockRestrictions#ad399cee as nil")
	}
	b.PutID(ChannelsSetBoostsToUnblockRestrictionsRequestTypeID)
	return s.EncodeBare(b)
}

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

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

// DecodeBare implements bin.BareDecoder.
func (s *ChannelsSetBoostsToUnblockRestrictionsRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode channels.setBoostsToUnblockRestrictions#ad399cee to nil")
	}
	{
		value, err := DecodeInputChannel(b)
		if err != nil {
			return fmt.Errorf("unable to decode channels.setBoostsToUnblockRestrictions#ad399cee: field channel: %w", err)
		}
		s.Channel = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode channels.setBoostsToUnblockRestrictions#ad399cee: field boosts: %w", err)
		}
		s.Boosts = value
	}
	return nil
}

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

// GetBoosts returns value of Boosts field.
func (s *ChannelsSetBoostsToUnblockRestrictionsRequest) GetBoosts() (value int) {
	if s == nil {
		return
	}
	return s.Boosts
}

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

// ChannelsSetBoostsToUnblockRestrictions invokes method channels.setBoostsToUnblockRestrictions#ad399cee returning error if any.
// Admins with ban_users admin rights »¹ may allow users that apply a certain number of
// booosts »² to the group to bypass slow mode »³ and other »⁴ supergroup
// restrictions, see here »⁵ for more info.
//
// Links:
//  1. https://core.telegram.org/constructor/chatAdminRights
//  2. https://core.telegram.org/api/boost
//  3. https://core.telegram.org/method/channels.toggleSlowMode
//  4. https://core.telegram.org/api/rights#default-rights
//  5. https://core.telegram.org/api/boost#bypass-slowmode-and-chat-restrictions
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//
// See https://core.telegram.org/method/channels.setBoostsToUnblockRestrictions for reference.
func (c *Client) ChannelsSetBoostsToUnblockRestrictions(ctx context.Context, request *ChannelsSetBoostsToUnblockRestrictionsRequest) (UpdatesClass, error) {
	var result UpdatesBox

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