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

// MessagesReportSponsoredMessageRequest represents TL type `messages.reportSponsoredMessage#12cbf0c4`.
// Report a sponsored message »¹, see here »² for more info on the full flow.
//
// Links:
//  1. https://core.telegram.org/api/sponsored-messages
//  2. https://core.telegram.org/api/sponsored-messages#reporting-sponsored-messages
//
// See https://core.telegram.org/method/messages.reportSponsoredMessage for reference.
type MessagesReportSponsoredMessageRequest struct {
	// The ad's unique ID.
	RandomID []byte
	// Chosen report option, initially an empty string, see here »¹ for more info on the
	// full flow.
	//
	// Links:
	//  1) https://core.telegram.org/api/sponsored-messages#reporting-sponsored-messages
	Option []byte
}

// MessagesReportSponsoredMessageRequestTypeID is TL type id of MessagesReportSponsoredMessageRequest.
const MessagesReportSponsoredMessageRequestTypeID = 0x12cbf0c4

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

func (r *MessagesReportSponsoredMessageRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.RandomID == nil) {
		return false
	}
	if !(r.Option == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesReportSponsoredMessageRequest from given interface.
func (r *MessagesReportSponsoredMessageRequest) FillFrom(from interface {
	GetRandomID() (value []byte)
	GetOption() (value []byte)
}) {
	r.RandomID = from.GetRandomID()
	r.Option = from.GetOption()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesReportSponsoredMessageRequest) TypeName() string {
	return "messages.reportSponsoredMessage"
}

// TypeInfo returns info about TL type.
func (r *MessagesReportSponsoredMessageRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.reportSponsoredMessage",
		ID:   MessagesReportSponsoredMessageRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "Option",
			SchemaName: "option",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *MessagesReportSponsoredMessageRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode messages.reportSponsoredMessage#12cbf0c4 as nil")
	}
	b.PutID(MessagesReportSponsoredMessageRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *MessagesReportSponsoredMessageRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode messages.reportSponsoredMessage#12cbf0c4 as nil")
	}
	b.PutBytes(r.RandomID)
	b.PutBytes(r.Option)
	return nil
}

// Decode implements bin.Decoder.
func (r *MessagesReportSponsoredMessageRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode messages.reportSponsoredMessage#12cbf0c4 to nil")
	}
	if err := b.ConsumeID(MessagesReportSponsoredMessageRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.reportSponsoredMessage#12cbf0c4: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *MessagesReportSponsoredMessageRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode messages.reportSponsoredMessage#12cbf0c4 to nil")
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode messages.reportSponsoredMessage#12cbf0c4: field random_id: %w", err)
		}
		r.RandomID = value
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode messages.reportSponsoredMessage#12cbf0c4: field option: %w", err)
		}
		r.Option = value
	}
	return nil
}

// GetRandomID returns value of RandomID field.
func (r *MessagesReportSponsoredMessageRequest) GetRandomID() (value []byte) {
	if r == nil {
		return
	}
	return r.RandomID
}

// GetOption returns value of Option field.
func (r *MessagesReportSponsoredMessageRequest) GetOption() (value []byte) {
	if r == nil {
		return
	}
	return r.Option
}

// MessagesReportSponsoredMessage invokes method messages.reportSponsoredMessage#12cbf0c4 returning error if any.
// Report a sponsored message »¹, see here »² for more info on the full flow.
//
// Links:
//  1. https://core.telegram.org/api/sponsored-messages
//  2. https://core.telegram.org/api/sponsored-messages#reporting-sponsored-messages
//
// See https://core.telegram.org/method/messages.reportSponsoredMessage for reference.
func (c *Client) MessagesReportSponsoredMessage(ctx context.Context, request *MessagesReportSponsoredMessageRequest) (ChannelsSponsoredMessageReportResultClass, error) {
	var result ChannelsSponsoredMessageReportResultBox

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