// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

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

// MessagesTranslateTextRequest represents TL type `messages.translateText#63183030`.
// Translate a given text.
// Styled text entities¹ will only be preserved for Telegram Premium² users.
//
// Links:
//  1. https://core.telegram.org/api/entities
//  2. https://core.telegram.org/api/premium
//
// See https://core.telegram.org/method/messages.translateText for reference.
type MessagesTranslateTextRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If the text is a chat message, the peer ID
	//
	// Use SetPeer and GetPeer helpers.
	Peer InputPeerClass
	// A list of message IDs to translate
	//
	// Use SetID and GetID helpers.
	ID []int
	// A list of styled messages to translate
	//
	// Use SetText and GetText helpers.
	Text []TextWithEntities
	// Two-letter ISO 639-1 language code of the language to which the message is translated
	ToLang string
}

// MessagesTranslateTextRequestTypeID is TL type id of MessagesTranslateTextRequest.
const MessagesTranslateTextRequestTypeID = 0x63183030

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

func ( *MessagesTranslateTextRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.ID == nil) {
		return false
	}
	if !(.Text == nil) {
		return false
	}
	if !(.ToLang == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesTranslateTextRequest from given interface.
func ( *MessagesTranslateTextRequest) ( interface {
	() ( InputPeerClass,  bool)
	() ( []int,  bool)
	() ( []TextWithEntities,  bool)
	() ( string)
}) {
	if ,  := .();  {
		.Peer = 
	}

	if ,  := .();  {
		.ID = 
	}

	if ,  := .();  {
		.Text = 
	}

	.ToLang = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesTranslateTextRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.translateText",
		ID:   MessagesTranslateTextRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ID",
			SchemaName: "id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Text",
			SchemaName: "text",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ToLang",
			SchemaName: "to_lang",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesTranslateTextRequest) () {
	if !(.Peer == nil) {
		.Flags.Set(0)
	}
	if !(.ID == nil) {
		.Flags.Set(0)
	}
	if !(.Text == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesTranslateTextRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.translateText#63183030 as nil")
	}
	.PutID(MessagesTranslateTextRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesTranslateTextRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.translateText#63183030 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.translateText#63183030: field flags: %w", )
	}
	if .Flags.Has(0) {
		if .Peer == nil {
			return fmt.Errorf("unable to encode messages.translateText#63183030: field peer is nil")
		}
		if  := .Peer.Encode();  != nil {
			return fmt.Errorf("unable to encode messages.translateText#63183030: field peer: %w", )
		}
	}
	if .Flags.Has(0) {
		.PutVectorHeader(len(.ID))
		for ,  := range .ID {
			.PutInt()
		}
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.Text))
		for ,  := range .Text {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode messages.translateText#63183030: field text element with index %d: %w", , )
			}
		}
	}
	.PutString(.ToLang)
	return nil
}

// Decode implements bin.Decoder.
func ( *MessagesTranslateTextRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.translateText#63183030 to nil")
	}
	if  := .ConsumeID(MessagesTranslateTextRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.translateText#63183030: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessagesTranslateTextRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.translateText#63183030 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.translateText#63183030: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.translateText#63183030: field peer: %w", )
		}
		.Peer = 
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.translateText#63183030: field id: %w", )
		}

		if  > 0 {
			.ID = make([]int, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .Int()
			if  != nil {
				return fmt.Errorf("unable to decode messages.translateText#63183030: field id: %w", )
			}
			.ID = append(.ID, )
		}
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.translateText#63183030: field text: %w", )
		}

		if  > 0 {
			.Text = make([]TextWithEntities, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  TextWithEntities
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode messages.translateText#63183030: field text: %w", )
			}
			.Text = append(.Text, )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.translateText#63183030: field to_lang: %w", )
		}
		.ToLang = 
	}
	return nil
}

// SetPeer sets value of Peer conditional field.
func ( *MessagesTranslateTextRequest) ( InputPeerClass) {
	.Flags.Set(0)
	.Peer = 
}

// GetPeer returns value of Peer conditional field and
// boolean which is true if field was set.
func ( *MessagesTranslateTextRequest) () ( InputPeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Peer, true
}

// SetID sets value of ID conditional field.
func ( *MessagesTranslateTextRequest) ( []int) {
	.Flags.Set(0)
	.ID = 
}

// GetID returns value of ID conditional field and
// boolean which is true if field was set.
func ( *MessagesTranslateTextRequest) () ( []int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .ID, true
}

// SetText sets value of Text conditional field.
func ( *MessagesTranslateTextRequest) ( []TextWithEntities) {
	.Flags.Set(1)
	.Text = 
}

// GetText returns value of Text conditional field and
// boolean which is true if field was set.
func ( *MessagesTranslateTextRequest) () ( []TextWithEntities,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Text, true
}

// GetToLang returns value of ToLang field.
func ( *MessagesTranslateTextRequest) () ( string) {
	if  == nil {
		return
	}
	return .ToLang
}

// MessagesTranslateText invokes method messages.translateText#63183030 returning error if any.
// Translate a given text.
// Styled text entities¹ will only be preserved for Telegram Premium² users.
//
// Links:
//  1. https://core.telegram.org/api/entities
//  2. https://core.telegram.org/api/premium
//
// Possible errors:
//
//	400 INPUT_TEXT_EMPTY: The specified text is empty.
//	400 MSG_ID_INVALID: Invalid message ID provided.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	400 TO_LANG_INVALID: The specified destination language is invalid.
//
// See https://core.telegram.org/method/messages.translateText for reference.
func ( *Client) ( context.Context,  *MessagesTranslateTextRequest) (*MessagesTranslateResult, error) {
	var  MessagesTranslateResult

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return &, nil
}