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

// InputReplyToMessage represents TL type `inputReplyToMessage#22c0f6d5`.
// Reply to a message.
//
// See https://core.telegram.org/constructor/inputReplyToMessage for reference.
type InputReplyToMessage struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The message ID to reply to.
	ReplyToMsgID int
	// This field must contain the topic ID only when replying to messages in forum topics
	// different from the "General" topic (i.e. reply_to_msg_id is set and reply_to_msg_id !=
	// topicID and topicID != 1).  If the replied-to message is deleted before the method
	// finishes execution, the value in this field will be used to send the message to the
	// correct topic, instead of the "General" topic.
	//
	// Use SetTopMsgID and GetTopMsgID helpers.
	TopMsgID int
	// Used to reply to messages sent to another chat (specified here), can only be used for
	// non-protected chats and messages.
	//
	// Use SetReplyToPeerID and GetReplyToPeerID helpers.
	ReplyToPeerID InputPeerClass
	// Used to quote-reply to only a certain section (specified here) of the original message.
	//
	// Use SetQuoteText and GetQuoteText helpers.
	QuoteText string
	// Message entities for styled text¹ from the quote_text field.
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//
	// Use SetQuoteEntities and GetQuoteEntities helpers.
	QuoteEntities []MessageEntityClass
	// Offset of the message quote_text within the original message (in UTF-16 code units¹).
	//
	// Links:
	//  1) https://core.telegram.org/api/entities#entity-length
	//
	// Use SetQuoteOffset and GetQuoteOffset helpers.
	QuoteOffset int
}

// InputReplyToMessageTypeID is TL type id of InputReplyToMessage.
const InputReplyToMessageTypeID = 0x22c0f6d5

// construct implements constructor of InputReplyToClass.
func ( InputReplyToMessage) () InputReplyToClass { return & }

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

	_ InputReplyToClass = &InputReplyToMessage{}
)

func ( *InputReplyToMessage) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.ReplyToMsgID == 0) {
		return false
	}
	if !(.TopMsgID == 0) {
		return false
	}
	if !(.ReplyToPeerID == nil) {
		return false
	}
	if !(.QuoteText == "") {
		return false
	}
	if !(.QuoteEntities == nil) {
		return false
	}
	if !(.QuoteOffset == 0) {
		return false
	}

	return true
}

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

// FillFrom fills InputReplyToMessage from given interface.
func ( *InputReplyToMessage) ( interface {
	() ( int)
	() ( int,  bool)
	() ( InputPeerClass,  bool)
	() ( string,  bool)
	() ( []MessageEntityClass,  bool)
	() ( int,  bool)
}) {
	.ReplyToMsgID = .()
	if ,  := .();  {
		.TopMsgID = 
	}

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

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *InputReplyToMessage) () tdp.Type {
	 := tdp.Type{
		Name: "inputReplyToMessage",
		ID:   InputReplyToMessageTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ReplyToMsgID",
			SchemaName: "reply_to_msg_id",
		},
		{
			Name:       "TopMsgID",
			SchemaName: "top_msg_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ReplyToPeerID",
			SchemaName: "reply_to_peer_id",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "QuoteText",
			SchemaName: "quote_text",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "QuoteEntities",
			SchemaName: "quote_entities",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "QuoteOffset",
			SchemaName: "quote_offset",
			Null:       !.Flags.Has(4),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *InputReplyToMessage) () {
	if !(.TopMsgID == 0) {
		.Flags.Set(0)
	}
	if !(.ReplyToPeerID == nil) {
		.Flags.Set(1)
	}
	if !(.QuoteText == "") {
		.Flags.Set(2)
	}
	if !(.QuoteEntities == nil) {
		.Flags.Set(3)
	}
	if !(.QuoteOffset == 0) {
		.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func ( *InputReplyToMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode inputReplyToMessage#22c0f6d5 as nil")
	}
	.PutID(InputReplyToMessageTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *InputReplyToMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode inputReplyToMessage#22c0f6d5 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode inputReplyToMessage#22c0f6d5: field flags: %w", )
	}
	.PutInt(.ReplyToMsgID)
	if .Flags.Has(0) {
		.PutInt(.TopMsgID)
	}
	if .Flags.Has(1) {
		if .ReplyToPeerID == nil {
			return fmt.Errorf("unable to encode inputReplyToMessage#22c0f6d5: field reply_to_peer_id is nil")
		}
		if  := .ReplyToPeerID.Encode();  != nil {
			return fmt.Errorf("unable to encode inputReplyToMessage#22c0f6d5: field reply_to_peer_id: %w", )
		}
	}
	if .Flags.Has(2) {
		.PutString(.QuoteText)
	}
	if .Flags.Has(3) {
		.PutVectorHeader(len(.QuoteEntities))
		for ,  := range .QuoteEntities {
			if  == nil {
				return fmt.Errorf("unable to encode inputReplyToMessage#22c0f6d5: field quote_entities element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode inputReplyToMessage#22c0f6d5: field quote_entities element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(4) {
		.PutInt(.QuoteOffset)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *InputReplyToMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode inputReplyToMessage#22c0f6d5 to nil")
	}
	if  := .ConsumeID(InputReplyToMessageTypeID);  != nil {
		return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *InputReplyToMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode inputReplyToMessage#22c0f6d5 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: field reply_to_msg_id: %w", )
		}
		.ReplyToMsgID = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: field top_msg_id: %w", )
		}
		.TopMsgID = 
	}
	if .Flags.Has(1) {
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: field reply_to_peer_id: %w", )
		}
		.ReplyToPeerID = 
	}
	if .Flags.Has(2) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: field quote_text: %w", )
		}
		.QuoteText = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: field quote_entities: %w", )
		}

		if  > 0 {
			.QuoteEntities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: field quote_entities: %w", )
			}
			.QuoteEntities = append(.QuoteEntities, )
		}
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode inputReplyToMessage#22c0f6d5: field quote_offset: %w", )
		}
		.QuoteOffset = 
	}
	return nil
}

// GetReplyToMsgID returns value of ReplyToMsgID field.
func ( *InputReplyToMessage) () ( int) {
	if  == nil {
		return
	}
	return .ReplyToMsgID
}

// SetTopMsgID sets value of TopMsgID conditional field.
func ( *InputReplyToMessage) ( int) {
	.Flags.Set(0)
	.TopMsgID = 
}

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

// SetReplyToPeerID sets value of ReplyToPeerID conditional field.
func ( *InputReplyToMessage) ( InputPeerClass) {
	.Flags.Set(1)
	.ReplyToPeerID = 
}

// GetReplyToPeerID returns value of ReplyToPeerID conditional field and
// boolean which is true if field was set.
func ( *InputReplyToMessage) () ( InputPeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .ReplyToPeerID, true
}

// SetQuoteText sets value of QuoteText conditional field.
func ( *InputReplyToMessage) ( string) {
	.Flags.Set(2)
	.QuoteText = 
}

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

// SetQuoteEntities sets value of QuoteEntities conditional field.
func ( *InputReplyToMessage) ( []MessageEntityClass) {
	.Flags.Set(3)
	.QuoteEntities = 
}

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

// SetQuoteOffset sets value of QuoteOffset conditional field.
func ( *InputReplyToMessage) ( int) {
	.Flags.Set(4)
	.QuoteOffset = 
}

// GetQuoteOffset returns value of QuoteOffset conditional field and
// boolean which is true if field was set.
func ( *InputReplyToMessage) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .QuoteOffset, true
}

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

// InputReplyToStory represents TL type `inputReplyToStory#15b0f283`.
// Reply to a story.
//
// See https://core.telegram.org/constructor/inputReplyToStory for reference.
type InputReplyToStory struct {
	// ID of the user that posted the story.
	UserID InputUserClass
	// ID of the story to reply to.
	StoryID int
}

// InputReplyToStoryTypeID is TL type id of InputReplyToStory.
const InputReplyToStoryTypeID = 0x15b0f283

// construct implements constructor of InputReplyToClass.
func ( InputReplyToStory) () InputReplyToClass { return & }

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

	_ InputReplyToClass = &InputReplyToStory{}
)

func ( *InputReplyToStory) () bool {
	if  == nil {
		return true
	}
	if !(.UserID == nil) {
		return false
	}
	if !(.StoryID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills InputReplyToStory from given interface.
func ( *InputReplyToStory) ( interface {
	() ( InputUserClass)
	() ( int)
}) {
	.UserID = .()
	.StoryID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *InputReplyToStory) () tdp.Type {
	 := tdp.Type{
		Name: "inputReplyToStory",
		ID:   InputReplyToStoryTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "StoryID",
			SchemaName: "story_id",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *InputReplyToStory) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode inputReplyToStory#15b0f283 as nil")
	}
	.PutID(InputReplyToStoryTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *InputReplyToStory) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode inputReplyToStory#15b0f283 as nil")
	}
	if .UserID == nil {
		return fmt.Errorf("unable to encode inputReplyToStory#15b0f283: field user_id is nil")
	}
	if  := .UserID.Encode();  != nil {
		return fmt.Errorf("unable to encode inputReplyToStory#15b0f283: field user_id: %w", )
	}
	.PutInt(.StoryID)
	return nil
}

// Decode implements bin.Decoder.
func ( *InputReplyToStory) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode inputReplyToStory#15b0f283 to nil")
	}
	if  := .ConsumeID(InputReplyToStoryTypeID);  != nil {
		return fmt.Errorf("unable to decode inputReplyToStory#15b0f283: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *InputReplyToStory) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode inputReplyToStory#15b0f283 to nil")
	}
	{
		,  := DecodeInputUser()
		if  != nil {
			return fmt.Errorf("unable to decode inputReplyToStory#15b0f283: field user_id: %w", )
		}
		.UserID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode inputReplyToStory#15b0f283: field story_id: %w", )
		}
		.StoryID = 
	}
	return nil
}

// GetUserID returns value of UserID field.
func ( *InputReplyToStory) () ( InputUserClass) {
	if  == nil {
		return
	}
	return .UserID
}

// GetStoryID returns value of StoryID field.
func ( *InputReplyToStory) () ( int) {
	if  == nil {
		return
	}
	return .StoryID
}

// InputReplyToClassName is schema name of InputReplyToClass.
const InputReplyToClassName = "InputReplyTo"

// InputReplyToClass represents InputReplyTo generic type.
//
// See https://core.telegram.org/type/InputReplyTo for reference.
//
// Example:
//
//	g, err := tg.DecodeInputReplyTo(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.InputReplyToMessage: // inputReplyToMessage#22c0f6d5
//	case *tg.InputReplyToStory: // inputReplyToStory#15b0f283
//	default: panic(v)
//	}
type InputReplyToClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() InputReplyToClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool
}

// DecodeInputReplyTo implements binary de-serialization for InputReplyToClass.
func ( *bin.Buffer) (InputReplyToClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case InputReplyToMessageTypeID:
		// Decoding inputReplyToMessage#22c0f6d5.
		 := InputReplyToMessage{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode InputReplyToClass: %w", )
		}
		return &, nil
	case InputReplyToStoryTypeID:
		// Decoding inputReplyToStory#15b0f283.
		 := InputReplyToStory{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode InputReplyToClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode InputReplyToClass: %w", bin.NewUnexpectedID())
	}
}

// InputReplyTo boxes the InputReplyToClass providing a helper.
type InputReplyToBox struct {
	InputReplyTo InputReplyToClass
}

// Decode implements bin.Decoder for InputReplyToBox.
func ( *InputReplyToBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode InputReplyToBox to nil")
	}
	,  := DecodeInputReplyTo()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.InputReplyTo = 
	return nil
}

// Encode implements bin.Encode for InputReplyToBox.
func ( *InputReplyToBox) ( *bin.Buffer) error {
	if  == nil || .InputReplyTo == nil {
		return fmt.Errorf("unable to encode InputReplyToClass as nil")
	}
	return .InputReplyTo.Encode()
}