// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// ChannelsReportSpamRequest represents TL type `channels.reportSpam#f44a8315`.
// Reports some messages from a user in a supergroup as spam; requires administrator
// rights in the supergroup
//
// See https://core.telegram.org/method/channels.reportSpam for reference.
type ChannelsReportSpamRequest struct {
	// Supergroup
	Channel InputChannelClass
	// Participant whose messages should be reported
	Participant InputPeerClass
	// IDs of spam messages
	ID []int
}

// ChannelsReportSpamRequestTypeID is TL type id of ChannelsReportSpamRequest.
const ChannelsReportSpamRequestTypeID = 0xf44a8315

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

func (r *ChannelsReportSpamRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.Channel == nil) {
		return false
	}
	if !(r.Participant == nil) {
		return false
	}
	if !(r.ID == nil) {
		return false
	}

	return true
}

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

// FillFrom fills ChannelsReportSpamRequest from given interface.
func (r *ChannelsReportSpamRequest) FillFrom(from interface {
	GetChannel() (value InputChannelClass)
	GetParticipant() (value InputPeerClass)
	GetID() (value []int)
}) {
	r.Channel = from.GetChannel()
	r.Participant = from.GetParticipant()
	r.ID = from.GetID()
}

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

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

// TypeInfo returns info about TL type.
func (r *ChannelsReportSpamRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "channels.reportSpam",
		ID:   ChannelsReportSpamRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Channel",
			SchemaName: "channel",
		},
		{
			Name:       "Participant",
			SchemaName: "participant",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *ChannelsReportSpamRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode channels.reportSpam#f44a8315 as nil")
	}
	b.PutID(ChannelsReportSpamRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ChannelsReportSpamRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode channels.reportSpam#f44a8315 as nil")
	}
	if r.Channel == nil {
		return fmt.Errorf("unable to encode channels.reportSpam#f44a8315: field channel is nil")
	}
	if err := r.Channel.Encode(b); err != nil {
		return fmt.Errorf("unable to encode channels.reportSpam#f44a8315: field channel: %w", err)
	}
	if r.Participant == nil {
		return fmt.Errorf("unable to encode channels.reportSpam#f44a8315: field participant is nil")
	}
	if err := r.Participant.Encode(b); err != nil {
		return fmt.Errorf("unable to encode channels.reportSpam#f44a8315: field participant: %w", err)
	}
	b.PutVectorHeader(len(r.ID))
	for _, v := range r.ID {
		b.PutInt(v)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (r *ChannelsReportSpamRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode channels.reportSpam#f44a8315 to nil")
	}
	{
		value, err := DecodeInputChannel(b)
		if err != nil {
			return fmt.Errorf("unable to decode channels.reportSpam#f44a8315: field channel: %w", err)
		}
		r.Channel = value
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode channels.reportSpam#f44a8315: field participant: %w", err)
		}
		r.Participant = value
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode channels.reportSpam#f44a8315: field id: %w", err)
		}

		if headerLen > 0 {
			r.ID = make([]int, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int()
			if err != nil {
				return fmt.Errorf("unable to decode channels.reportSpam#f44a8315: field id: %w", err)
			}
			r.ID = append(r.ID, value)
		}
	}
	return nil
}

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

// GetParticipant returns value of Participant field.
func (r *ChannelsReportSpamRequest) GetParticipant() (value InputPeerClass) {
	if r == nil {
		return
	}
	return r.Participant
}

// GetID returns value of ID field.
func (r *ChannelsReportSpamRequest) GetID() (value []int) {
	if r == nil {
		return
	}
	return r.ID
}

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

// ChannelsReportSpam invokes method channels.reportSpam#f44a8315 returning error if any.
// Reports some messages from a user in a supergroup as spam; requires administrator
// rights in the supergroup
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	400 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
//	400 INPUT_USER_DEACTIVATED: The specified user was deleted.
//	400 USER_ID_INVALID: The provided user ID is invalid.
//
// See https://core.telegram.org/method/channels.reportSpam for reference.
func (c *Client) ChannelsReportSpam(ctx context.Context, request *ChannelsReportSpamRequest) (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
}
