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

// MessagesGetWebPagePreviewRequest represents TL type `messages.getWebPagePreview#8b68b0cc`.
// Get preview of webpage
//
// See https://core.telegram.org/method/messages.getWebPagePreview for reference.
type MessagesGetWebPagePreviewRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Message from which to extract the preview
	Message string
	// Message entities for styled text¹
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//
	// Use SetEntities and GetEntities helpers.
	Entities []MessageEntityClass
}

// MessagesGetWebPagePreviewRequestTypeID is TL type id of MessagesGetWebPagePreviewRequest.
const MessagesGetWebPagePreviewRequestTypeID = 0x8b68b0cc

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

func ( *MessagesGetWebPagePreviewRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Message == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesGetWebPagePreviewRequest from given interface.
func ( *MessagesGetWebPagePreviewRequest) ( interface {
	() ( string)
	() ( []MessageEntityClass,  bool)
}) {
	.Message = .()
	if ,  := .();  {
		.Entities = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesGetWebPagePreviewRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.getWebPagePreview",
		ID:   MessagesGetWebPagePreviewRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Message",
			SchemaName: "message",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
			Null:       !.Flags.Has(3),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesGetWebPagePreviewRequest) () {
	if !(.Entities == nil) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesGetWebPagePreviewRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.getWebPagePreview#8b68b0cc as nil")
	}
	.PutID(MessagesGetWebPagePreviewRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesGetWebPagePreviewRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.getWebPagePreview#8b68b0cc as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.getWebPagePreview#8b68b0cc: field flags: %w", )
	}
	.PutString(.Message)
	if .Flags.Has(3) {
		.PutVectorHeader(len(.Entities))
		for ,  := range .Entities {
			if  == nil {
				return fmt.Errorf("unable to encode messages.getWebPagePreview#8b68b0cc: field entities element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode messages.getWebPagePreview#8b68b0cc: field entities element with index %d: %w", , )
			}
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesGetWebPagePreviewRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.getWebPagePreview#8b68b0cc to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.getWebPagePreview#8b68b0cc: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getWebPagePreview#8b68b0cc: field message: %w", )
		}
		.Message = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getWebPagePreview#8b68b0cc: field entities: %w", )
		}

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

// GetMessage returns value of Message field.
func ( *MessagesGetWebPagePreviewRequest) () ( string) {
	if  == nil {
		return
	}
	return .Message
}

// SetEntities sets value of Entities conditional field.
func ( *MessagesGetWebPagePreviewRequest) ( []MessageEntityClass) {
	.Flags.Set(3)
	.Entities = 
}

// GetEntities returns value of Entities conditional field and
// boolean which is true if field was set.
func ( *MessagesGetWebPagePreviewRequest) () ( []MessageEntityClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Entities, true
}

// MapEntities returns field Entities wrapped in MessageEntityClassArray helper.
func ( *MessagesGetWebPagePreviewRequest) () ( MessageEntityClassArray,  bool) {
	if !.Flags.Has(3) {
		return , false
	}
	return MessageEntityClassArray(.Entities), true
}

// MessagesGetWebPagePreview invokes method messages.getWebPagePreview#8b68b0cc returning error if any.
// Get preview of webpage
//
// Possible errors:
//
//	400 ENTITY_BOUNDS_INVALID: A specified entity offset or length is invalid, see here » for info on how to properly compute the entity offset/length.
//	400 MESSAGE_EMPTY: The provided message is empty.
//
// See https://core.telegram.org/method/messages.getWebPagePreview for reference.
func ( *Client) ( context.Context,  *MessagesGetWebPagePreviewRequest) (MessageMediaClass, error) {
	var  MessageMediaBox

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