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

// MessagesSummarizeTextRequest represents TL type `messages.summarizeText#abbbd346`.
//
// See https://core.telegram.org/method/messages.summarizeText for reference.
type MessagesSummarizeTextRequest struct {
	// Flags field of MessagesSummarizeTextRequest.
	Flags bin.Fields
	// Peer field of MessagesSummarizeTextRequest.
	Peer InputPeerClass
	// ID field of MessagesSummarizeTextRequest.
	ID int
	// ToLang field of MessagesSummarizeTextRequest.
	//
	// Use SetToLang and GetToLang helpers.
	ToLang string
	// Tone field of MessagesSummarizeTextRequest.
	//
	// Use SetTone and GetTone helpers.
	Tone string
}

// MessagesSummarizeTextRequestTypeID is TL type id of MessagesSummarizeTextRequest.
const MessagesSummarizeTextRequestTypeID = 0xabbbd346

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

func (s *MessagesSummarizeTextRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Flags.Zero()) {
		return false
	}
	if !(s.Peer == nil) {
		return false
	}
	if !(s.ID == 0) {
		return false
	}
	if !(s.ToLang == "") {
		return false
	}
	if !(s.Tone == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSummarizeTextRequest from given interface.
func (s *MessagesSummarizeTextRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetID() (value int)
	GetToLang() (value string, ok bool)
	GetTone() (value string, ok bool)
}) {
	s.Peer = from.GetPeer()
	s.ID = from.GetID()
	if val, ok := from.GetToLang(); ok {
		s.ToLang = val
	}

	if val, ok := from.GetTone(); ok {
		s.Tone = val
	}

}

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

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

// TypeInfo returns info about TL type.
func (s *MessagesSummarizeTextRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.summarizeText",
		ID:   MessagesSummarizeTextRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "ToLang",
			SchemaName: "to_lang",
			Null:       !s.Flags.Has(0),
		},
		{
			Name:       "Tone",
			SchemaName: "tone",
			Null:       !s.Flags.Has(2),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (s *MessagesSummarizeTextRequest) SetFlags() {
	if !(s.ToLang == "") {
		s.Flags.Set(0)
	}
	if !(s.Tone == "") {
		s.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func (s *MessagesSummarizeTextRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.summarizeText#abbbd346 as nil")
	}
	b.PutID(MessagesSummarizeTextRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *MessagesSummarizeTextRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.summarizeText#abbbd346 as nil")
	}
	s.SetFlags()
	if err := s.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.summarizeText#abbbd346: field flags: %w", err)
	}
	if s.Peer == nil {
		return fmt.Errorf("unable to encode messages.summarizeText#abbbd346: field peer is nil")
	}
	if err := s.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.summarizeText#abbbd346: field peer: %w", err)
	}
	b.PutInt(s.ID)
	if s.Flags.Has(0) {
		b.PutString(s.ToLang)
	}
	if s.Flags.Has(2) {
		b.PutString(s.Tone)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *MessagesSummarizeTextRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.summarizeText#abbbd346 to nil")
	}
	if err := b.ConsumeID(MessagesSummarizeTextRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.summarizeText#abbbd346: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *MessagesSummarizeTextRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.summarizeText#abbbd346 to nil")
	}
	{
		if err := s.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messages.summarizeText#abbbd346: field flags: %w", err)
		}
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.summarizeText#abbbd346: field peer: %w", err)
		}
		s.Peer = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.summarizeText#abbbd346: field id: %w", err)
		}
		s.ID = value
	}
	if s.Flags.Has(0) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.summarizeText#abbbd346: field to_lang: %w", err)
		}
		s.ToLang = value
	}
	if s.Flags.Has(2) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.summarizeText#abbbd346: field tone: %w", err)
		}
		s.Tone = value
	}
	return nil
}

// GetPeer returns value of Peer field.
func (s *MessagesSummarizeTextRequest) GetPeer() (value InputPeerClass) {
	if s == nil {
		return
	}
	return s.Peer
}

// GetID returns value of ID field.
func (s *MessagesSummarizeTextRequest) GetID() (value int) {
	if s == nil {
		return
	}
	return s.ID
}

// SetToLang sets value of ToLang conditional field.
func (s *MessagesSummarizeTextRequest) SetToLang(value string) {
	s.Flags.Set(0)
	s.ToLang = value
}

// GetToLang returns value of ToLang conditional field and
// boolean which is true if field was set.
func (s *MessagesSummarizeTextRequest) GetToLang() (value string, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(0) {
		return value, false
	}
	return s.ToLang, true
}

// SetTone sets value of Tone conditional field.
func (s *MessagesSummarizeTextRequest) SetTone(value string) {
	s.Flags.Set(2)
	s.Tone = value
}

// GetTone returns value of Tone conditional field and
// boolean which is true if field was set.
func (s *MessagesSummarizeTextRequest) GetTone() (value string, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(2) {
		return value, false
	}
	return s.Tone, true
}

// MessagesSummarizeText invokes method messages.summarizeText#abbbd346 returning error if any.
//
// See https://core.telegram.org/method/messages.summarizeText for reference.
func (c *Client) MessagesSummarizeText(ctx context.Context, request *MessagesSummarizeTextRequest) (*TextWithEntities, error) {
	var result TextWithEntities

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