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

// ChannelsRestrictSponsoredMessagesRequest represents TL type `channels.restrictSponsoredMessages#9ae91519`.
// Disable ads on the specified channel, for all users.
// Available only after reaching at least the boost level »¹ specified in the
// channel_restrict_sponsored_level_min »² config parameter.
//
// Links:
//  1. https://core.telegram.org/api/boost
//  2. https://core.telegram.org/api/config#channel-restrict-sponsored-level-min
//
// See https://core.telegram.org/method/channels.restrictSponsoredMessages for reference.
type ChannelsRestrictSponsoredMessagesRequest struct {
	// The channel.
	Channel InputChannelClass
	// Whether to disable or re-enable ads.
	Restricted bool
}

// ChannelsRestrictSponsoredMessagesRequestTypeID is TL type id of ChannelsRestrictSponsoredMessagesRequest.
const ChannelsRestrictSponsoredMessagesRequestTypeID = 0x9ae91519

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

func (r *ChannelsRestrictSponsoredMessagesRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.Channel == nil) {
		return false
	}
	if !(r.Restricted == false) {
		return false
	}

	return true
}

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

// FillFrom fills ChannelsRestrictSponsoredMessagesRequest from given interface.
func (r *ChannelsRestrictSponsoredMessagesRequest) FillFrom(from interface {
	GetChannel() (value InputChannelClass)
	GetRestricted() (value bool)
}) {
	r.Channel = from.GetChannel()
	r.Restricted = from.GetRestricted()
}

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

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

// TypeInfo returns info about TL type.
func (r *ChannelsRestrictSponsoredMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "channels.restrictSponsoredMessages",
		ID:   ChannelsRestrictSponsoredMessagesRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Channel",
			SchemaName: "channel",
		},
		{
			Name:       "Restricted",
			SchemaName: "restricted",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *ChannelsRestrictSponsoredMessagesRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode channels.restrictSponsoredMessages#9ae91519 as nil")
	}
	b.PutID(ChannelsRestrictSponsoredMessagesRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ChannelsRestrictSponsoredMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode channels.restrictSponsoredMessages#9ae91519 as nil")
	}
	if r.Channel == nil {
		return fmt.Errorf("unable to encode channels.restrictSponsoredMessages#9ae91519: field channel is nil")
	}
	if err := r.Channel.Encode(b); err != nil {
		return fmt.Errorf("unable to encode channels.restrictSponsoredMessages#9ae91519: field channel: %w", err)
	}
	b.PutBool(r.Restricted)
	return nil
}

// Decode implements bin.Decoder.
func (r *ChannelsRestrictSponsoredMessagesRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode channels.restrictSponsoredMessages#9ae91519 to nil")
	}
	if err := b.ConsumeID(ChannelsRestrictSponsoredMessagesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode channels.restrictSponsoredMessages#9ae91519: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *ChannelsRestrictSponsoredMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode channels.restrictSponsoredMessages#9ae91519 to nil")
	}
	{
		value, err := DecodeInputChannel(b)
		if err != nil {
			return fmt.Errorf("unable to decode channels.restrictSponsoredMessages#9ae91519: field channel: %w", err)
		}
		r.Channel = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode channels.restrictSponsoredMessages#9ae91519: field restricted: %w", err)
		}
		r.Restricted = value
	}
	return nil
}

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

// GetRestricted returns value of Restricted field.
func (r *ChannelsRestrictSponsoredMessagesRequest) GetRestricted() (value bool) {
	if r == nil {
		return
	}
	return r.Restricted
}

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

// ChannelsRestrictSponsoredMessages invokes method channels.restrictSponsoredMessages#9ae91519 returning error if any.
// Disable ads on the specified channel, for all users.
// Available only after reaching at least the boost level »¹ specified in the
// channel_restrict_sponsored_level_min »² config parameter.
//
// Links:
//  1. https://core.telegram.org/api/boost
//  2. https://core.telegram.org/api/config#channel-restrict-sponsored-level-min
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//
// See https://core.telegram.org/method/channels.restrictSponsoredMessages for reference.
func (c *Client) ChannelsRestrictSponsoredMessages(ctx context.Context, request *ChannelsRestrictSponsoredMessagesRequest) (UpdatesClass, error) {
	var result UpdatesBox

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