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

// SponsoredMessageReportOption represents TL type `sponsoredMessageReportOption#430d3150`.
// A report option for a sponsored message »¹.
//
// Links:
//  1. https://core.telegram.org/api/sponsored-messages#reporting-sponsored-messages
//
// See https://core.telegram.org/constructor/sponsoredMessageReportOption for reference.
type SponsoredMessageReportOption struct {
	// Localized description of the option.
	Text string
	// Option identifier to pass to channels.reportSponsoredMessage¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/channels.reportSponsoredMessage
	Option []byte
}

// SponsoredMessageReportOptionTypeID is TL type id of SponsoredMessageReportOption.
const SponsoredMessageReportOptionTypeID = 0x430d3150

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

func (s *SponsoredMessageReportOption) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Text == "") {
		return false
	}
	if !(s.Option == nil) {
		return false
	}

	return true
}

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

// FillFrom fills SponsoredMessageReportOption from given interface.
func (s *SponsoredMessageReportOption) FillFrom(from interface {
	GetText() (value string)
	GetOption() (value []byte)
}) {
	s.Text = from.GetText()
	s.Option = from.GetOption()
}

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

// TypeName returns name of type in TL schema.
func (*SponsoredMessageReportOption) TypeName() string {
	return "sponsoredMessageReportOption"
}

// TypeInfo returns info about TL type.
func (s *SponsoredMessageReportOption) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "sponsoredMessageReportOption",
		ID:   SponsoredMessageReportOptionTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Text",
			SchemaName: "text",
		},
		{
			Name:       "Option",
			SchemaName: "option",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SponsoredMessageReportOption) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode sponsoredMessageReportOption#430d3150 as nil")
	}
	b.PutID(SponsoredMessageReportOptionTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SponsoredMessageReportOption) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode sponsoredMessageReportOption#430d3150 as nil")
	}
	b.PutString(s.Text)
	b.PutBytes(s.Option)
	return nil
}

// Decode implements bin.Decoder.
func (s *SponsoredMessageReportOption) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode sponsoredMessageReportOption#430d3150 to nil")
	}
	if err := b.ConsumeID(SponsoredMessageReportOptionTypeID); err != nil {
		return fmt.Errorf("unable to decode sponsoredMessageReportOption#430d3150: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SponsoredMessageReportOption) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode sponsoredMessageReportOption#430d3150 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode sponsoredMessageReportOption#430d3150: field text: %w", err)
		}
		s.Text = value
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode sponsoredMessageReportOption#430d3150: field option: %w", err)
		}
		s.Option = value
	}
	return nil
}

// GetText returns value of Text field.
func (s *SponsoredMessageReportOption) GetText() (value string) {
	if s == nil {
		return
	}
	return s.Text
}

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