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

// MessageReplies represents TL type `messageReplies#83d60fc2`.
// Info about the comment section of a channel post, or a simple message thread¹
//
// Links:
//  1. https://core.telegram.org/api/threads
//
// See https://core.telegram.org/constructor/messageReplies for reference.
type MessageReplies struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this constructor contains information about the comment section of a channel
	// post, or a simple message thread¹
	//
	// Links:
	//  1) https://core.telegram.org/api/threads
	Comments bool
	// Contains the total number of replies in this thread or comment section.
	Replies int
	// PTS¹ of the message that started this thread.
	//
	// Links:
	//  1) https://core.telegram.org/api/updates
	RepliesPts int
	// For channel post comments, contains information about the last few comment posters for
	// a specific thread, to show a small list of commenter profile pictures in client
	// previews.
	//
	// Use SetRecentRepliers and GetRecentRepliers helpers.
	RecentRepliers []PeerClass
	// For channel post comments, contains the ID of the associated discussion supergroup¹
	//
	// Links:
	//  1) https://core.telegram.org/api/discussion
	//
	// Use SetChannelID and GetChannelID helpers.
	ChannelID int64
	// ID of the latest message in this thread or comment section.
	//
	// Use SetMaxID and GetMaxID helpers.
	MaxID int
	// Contains the ID of the latest read message in this thread or comment section.
	//
	// Use SetReadMaxID and GetReadMaxID helpers.
	ReadMaxID int
}

// MessageRepliesTypeID is TL type id of MessageReplies.
const MessageRepliesTypeID = 0x83d60fc2

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

func ( *MessageReplies) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Comments == false) {
		return false
	}
	if !(.Replies == 0) {
		return false
	}
	if !(.RepliesPts == 0) {
		return false
	}
	if !(.RecentRepliers == nil) {
		return false
	}
	if !(.ChannelID == 0) {
		return false
	}
	if !(.MaxID == 0) {
		return false
	}
	if !(.ReadMaxID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessageReplies from given interface.
func ( *MessageReplies) ( interface {
	() ( bool)
	() ( int)
	() ( int)
	() ( []PeerClass,  bool)
	() ( int64,  bool)
	() ( int,  bool)
	() ( int,  bool)
}) {
	.Comments = .()
	.Replies = .()
	.RepliesPts = .()
	if ,  := .();  {
		.RecentRepliers = 
	}

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *MessageReplies) () tdp.Type {
	 := tdp.Type{
		Name: "messageReplies",
		ID:   MessageRepliesTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Comments",
			SchemaName: "comments",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Replies",
			SchemaName: "replies",
		},
		{
			Name:       "RepliesPts",
			SchemaName: "replies_pts",
		},
		{
			Name:       "RecentRepliers",
			SchemaName: "recent_repliers",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ChannelID",
			SchemaName: "channel_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "MaxID",
			SchemaName: "max_id",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "ReadMaxID",
			SchemaName: "read_max_id",
			Null:       !.Flags.Has(3),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessageReplies) () {
	if !(.Comments == false) {
		.Flags.Set(0)
	}
	if !(.RecentRepliers == nil) {
		.Flags.Set(1)
	}
	if !(.ChannelID == 0) {
		.Flags.Set(0)
	}
	if !(.MaxID == 0) {
		.Flags.Set(2)
	}
	if !(.ReadMaxID == 0) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *MessageReplies) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageReplies#83d60fc2 as nil")
	}
	.PutID(MessageRepliesTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessageReplies) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageReplies#83d60fc2 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messageReplies#83d60fc2: field flags: %w", )
	}
	.PutInt(.Replies)
	.PutInt(.RepliesPts)
	if .Flags.Has(1) {
		.PutVectorHeader(len(.RecentRepliers))
		for ,  := range .RecentRepliers {
			if  == nil {
				return fmt.Errorf("unable to encode messageReplies#83d60fc2: field recent_repliers element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode messageReplies#83d60fc2: field recent_repliers element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(0) {
		.PutLong(.ChannelID)
	}
	if .Flags.Has(2) {
		.PutInt(.MaxID)
	}
	if .Flags.Has(3) {
		.PutInt(.ReadMaxID)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *MessageReplies) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messageReplies#83d60fc2 to nil")
	}
	if  := .ConsumeID(MessageRepliesTypeID);  != nil {
		return fmt.Errorf("unable to decode messageReplies#83d60fc2: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessageReplies) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messageReplies#83d60fc2 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messageReplies#83d60fc2: field flags: %w", )
		}
	}
	.Comments = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageReplies#83d60fc2: field replies: %w", )
		}
		.Replies = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageReplies#83d60fc2: field replies_pts: %w", )
		}
		.RepliesPts = 
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messageReplies#83d60fc2: field recent_repliers: %w", )
		}

		if  > 0 {
			.RecentRepliers = make([]PeerClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePeer()
			if  != nil {
				return fmt.Errorf("unable to decode messageReplies#83d60fc2: field recent_repliers: %w", )
			}
			.RecentRepliers = append(.RecentRepliers, )
		}
	}
	if .Flags.Has(0) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode messageReplies#83d60fc2: field channel_id: %w", )
		}
		.ChannelID = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageReplies#83d60fc2: field max_id: %w", )
		}
		.MaxID = 
	}
	if .Flags.Has(3) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageReplies#83d60fc2: field read_max_id: %w", )
		}
		.ReadMaxID = 
	}
	return nil
}

// SetComments sets value of Comments conditional field.
func ( *MessageReplies) ( bool) {
	if  {
		.Flags.Set(0)
		.Comments = true
	} else {
		.Flags.Unset(0)
		.Comments = false
	}
}

// GetComments returns value of Comments conditional field.
func ( *MessageReplies) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetReplies returns value of Replies field.
func ( *MessageReplies) () ( int) {
	if  == nil {
		return
	}
	return .Replies
}

// GetRepliesPts returns value of RepliesPts field.
func ( *MessageReplies) () ( int) {
	if  == nil {
		return
	}
	return .RepliesPts
}

// SetRecentRepliers sets value of RecentRepliers conditional field.
func ( *MessageReplies) ( []PeerClass) {
	.Flags.Set(1)
	.RecentRepliers = 
}

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

// SetChannelID sets value of ChannelID conditional field.
func ( *MessageReplies) ( int64) {
	.Flags.Set(0)
	.ChannelID = 
}

// GetChannelID returns value of ChannelID conditional field and
// boolean which is true if field was set.
func ( *MessageReplies) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .ChannelID, true
}

// SetMaxID sets value of MaxID conditional field.
func ( *MessageReplies) ( int) {
	.Flags.Set(2)
	.MaxID = 
}

// GetMaxID returns value of MaxID conditional field and
// boolean which is true if field was set.
func ( *MessageReplies) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .MaxID, true
}

// SetReadMaxID sets value of ReadMaxID conditional field.
func ( *MessageReplies) ( int) {
	.Flags.Set(3)
	.ReadMaxID = 
}

// GetReadMaxID returns value of ReadMaxID conditional field and
// boolean which is true if field was set.
func ( *MessageReplies) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .ReadMaxID, true
}

// MapRecentRepliers returns field RecentRepliers wrapped in PeerClassArray helper.
func ( *MessageReplies) () ( PeerClassArray,  bool) {
	if !.Flags.Has(1) {
		return , false
	}
	return PeerClassArray(.RecentRepliers), true
}