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

// MessagesDiscussionMessage represents TL type `messages.discussionMessage#a6341782`.
// Information about a message thread¹
//
// Links:
//  1. https://core.telegram.org/api/threads
//
// See https://core.telegram.org/constructor/messages.discussionMessage for reference.
type MessagesDiscussionMessage struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The messages from which the thread starts. The messages are returned in reverse
	// chronological order (i.e., in order of decreasing message ID).
	Messages []MessageClass
	// Message ID of latest reply in this thread¹
	//
	// Links:
	//  1) https://core.telegram.org/api/threads
	//
	// Use SetMaxID and GetMaxID helpers.
	MaxID int
	// Message ID of latest read incoming message in this thread¹
	//
	// Links:
	//  1) https://core.telegram.org/api/threads
	//
	// Use SetReadInboxMaxID and GetReadInboxMaxID helpers.
	ReadInboxMaxID int
	// Message ID of latest read outgoing message in this thread¹
	//
	// Links:
	//  1) https://core.telegram.org/api/threads
	//
	// Use SetReadOutboxMaxID and GetReadOutboxMaxID helpers.
	ReadOutboxMaxID int
	// Number of unread messages
	UnreadCount int
	// Chats mentioned in constructor
	Chats []ChatClass
	// Users mentioned in constructor
	Users []UserClass
}

// MessagesDiscussionMessageTypeID is TL type id of MessagesDiscussionMessage.
const MessagesDiscussionMessageTypeID = 0xa6341782

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

func ( *MessagesDiscussionMessage) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Messages == nil) {
		return false
	}
	if !(.MaxID == 0) {
		return false
	}
	if !(.ReadInboxMaxID == 0) {
		return false
	}
	if !(.ReadOutboxMaxID == 0) {
		return false
	}
	if !(.UnreadCount == 0) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesDiscussionMessage from given interface.
func ( *MessagesDiscussionMessage) ( interface {
	() ( []MessageClass)
	() ( int,  bool)
	() ( int,  bool)
	() ( int,  bool)
	() ( int)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Messages = .()
	if ,  := .();  {
		.MaxID = 
	}

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

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

	.UnreadCount = .()
	.Chats = .()
	.Users = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesDiscussionMessage) () tdp.Type {
	 := tdp.Type{
		Name: "messages.discussionMessage",
		ID:   MessagesDiscussionMessageTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Messages",
			SchemaName: "messages",
		},
		{
			Name:       "MaxID",
			SchemaName: "max_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ReadInboxMaxID",
			SchemaName: "read_inbox_max_id",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ReadOutboxMaxID",
			SchemaName: "read_outbox_max_id",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "UnreadCount",
			SchemaName: "unread_count",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesDiscussionMessage) () {
	if !(.MaxID == 0) {
		.Flags.Set(0)
	}
	if !(.ReadInboxMaxID == 0) {
		.Flags.Set(1)
	}
	if !(.ReadOutboxMaxID == 0) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesDiscussionMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.discussionMessage#a6341782 as nil")
	}
	.PutID(MessagesDiscussionMessageTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesDiscussionMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.discussionMessage#a6341782 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.discussionMessage#a6341782: field flags: %w", )
	}
	.PutVectorHeader(len(.Messages))
	for ,  := range .Messages {
		if  == nil {
			return fmt.Errorf("unable to encode messages.discussionMessage#a6341782: field messages element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.discussionMessage#a6341782: field messages element with index %d: %w", , )
		}
	}
	if .Flags.Has(0) {
		.PutInt(.MaxID)
	}
	if .Flags.Has(1) {
		.PutInt(.ReadInboxMaxID)
	}
	if .Flags.Has(2) {
		.PutInt(.ReadOutboxMaxID)
	}
	.PutInt(.UnreadCount)
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode messages.discussionMessage#a6341782: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.discussionMessage#a6341782: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode messages.discussionMessage#a6341782: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.discussionMessage#a6341782: field users element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesDiscussionMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.discussionMessage#a6341782 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field flags: %w", )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field messages: %w", )
		}

		if  > 0 {
			.Messages = make([]MessageClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessage()
			if  != nil {
				return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field messages: %w", )
			}
			.Messages = append(.Messages, )
		}
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field max_id: %w", )
		}
		.MaxID = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field read_inbox_max_id: %w", )
		}
		.ReadInboxMaxID = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field read_outbox_max_id: %w", )
		}
		.ReadOutboxMaxID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field unread_count: %w", )
		}
		.UnreadCount = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode messages.discussionMessage#a6341782: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	return nil
}

// GetMessages returns value of Messages field.
func ( *MessagesDiscussionMessage) () ( []MessageClass) {
	if  == nil {
		return
	}
	return .Messages
}

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

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

// SetReadInboxMaxID sets value of ReadInboxMaxID conditional field.
func ( *MessagesDiscussionMessage) ( int) {
	.Flags.Set(1)
	.ReadInboxMaxID = 
}

// GetReadInboxMaxID returns value of ReadInboxMaxID conditional field and
// boolean which is true if field was set.
func ( *MessagesDiscussionMessage) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .ReadInboxMaxID, true
}

// SetReadOutboxMaxID sets value of ReadOutboxMaxID conditional field.
func ( *MessagesDiscussionMessage) ( int) {
	.Flags.Set(2)
	.ReadOutboxMaxID = 
}

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

// GetUnreadCount returns value of UnreadCount field.
func ( *MessagesDiscussionMessage) () ( int) {
	if  == nil {
		return
	}
	return .UnreadCount
}

// GetChats returns value of Chats field.
func ( *MessagesDiscussionMessage) () ( []ChatClass) {
	if  == nil {
		return
	}
	return .Chats
}

// GetUsers returns value of Users field.
func ( *MessagesDiscussionMessage) () ( []UserClass) {
	if  == nil {
		return
	}
	return .Users
}

// MapMessages returns field Messages wrapped in MessageClassArray helper.
func ( *MessagesDiscussionMessage) () ( MessageClassArray) {
	return MessageClassArray(.Messages)
}

// MapChats returns field Chats wrapped in ChatClassArray helper.
func ( *MessagesDiscussionMessage) () ( ChatClassArray) {
	return ChatClassArray(.Chats)
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func ( *MessagesDiscussionMessage) () ( UserClassArray) {
	return UserClassArray(.Users)
}