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

// TextWithEntities represents TL type `textWithEntities#751f3146`.
// Styled text with message entities¹
//
// Links:
//  1. https://core.telegram.org/api/entities
//
// See https://core.telegram.org/constructor/textWithEntities for reference.
type TextWithEntities struct {
	// Text
	Text string
	// Message entities for styled text¹
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	Entities []MessageEntityClass
}

// TextWithEntitiesTypeID is TL type id of TextWithEntities.
const TextWithEntitiesTypeID = 0x751f3146

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

func ( *TextWithEntities) () bool {
	if  == nil {
		return true
	}
	if !(.Text == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}

	return true
}

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

// FillFrom fills TextWithEntities from given interface.
func ( *TextWithEntities) ( interface {
	() ( string)
	() ( []MessageEntityClass)
}) {
	.Text = .()
	.Entities = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *TextWithEntities) () tdp.Type {
	 := tdp.Type{
		Name: "textWithEntities",
		ID:   TextWithEntitiesTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Text",
			SchemaName: "text",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *TextWithEntities) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode textWithEntities#751f3146 as nil")
	}
	.PutID(TextWithEntitiesTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *TextWithEntities) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode textWithEntities#751f3146 as nil")
	}
	.PutString(.Text)
	.PutVectorHeader(len(.Entities))
	for ,  := range .Entities {
		if  == nil {
			return fmt.Errorf("unable to encode textWithEntities#751f3146: field entities element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode textWithEntities#751f3146: field entities element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *TextWithEntities) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode textWithEntities#751f3146 to nil")
	}
	if  := .ConsumeID(TextWithEntitiesTypeID);  != nil {
		return fmt.Errorf("unable to decode textWithEntities#751f3146: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *TextWithEntities) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode textWithEntities#751f3146 to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode textWithEntities#751f3146: field text: %w", )
		}
		.Text = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode textWithEntities#751f3146: field entities: %w", )
		}

		if  > 0 {
			.Entities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode textWithEntities#751f3146: field entities: %w", )
			}
			.Entities = append(.Entities, )
		}
	}
	return nil
}

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

// GetEntities returns value of Entities field.
func ( *TextWithEntities) () ( []MessageEntityClass) {
	if  == nil {
		return
	}
	return .Entities
}

// MapEntities returns field Entities wrapped in MessageEntityClassArray helper.
func ( *TextWithEntities) () ( MessageEntityClassArray) {
	return MessageEntityClassArray(.Entities)
}