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

// MessagesForumTopics represents TL type `messages.forumTopics#367617d3`.
// Contains information about multiple forum topics¹
//
// Links:
//  1. https://core.telegram.org/api/forum#forum-topics
//
// See https://core.telegram.org/constructor/messages.forumTopics for reference.
type MessagesForumTopics struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the returned topics are ordered by creation date; if set, pagination by
	// offset_date should use forumTopic¹.date; otherwise topics are ordered by the last
	// message date, so paginate by the date of the message² referenced by forumTopic³
	// top_message.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/forumTopic
	//  2) https://core.telegram.org/type/Message
	//  3) https://core.telegram.org/constructor/forumTopic
	OrderByCreateDate bool
	// Total number of topics matching query; may be more than the topics contained in topics
	// in which case pagination¹ is required.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Count int
	// Forum topics
	Topics []ForumTopicClass
	// Related messages (contains the messages mentioned by forumTopic¹.top_message).
	//
	// Links:
	//  1) https://core.telegram.org/constructor/forumTopic
	Messages []MessageClass
	// Related chats
	Chats []ChatClass
	// Related users
	Users []UserClass
	// Event count after generation¹
	//
	// Links:
	//  1) https://core.telegram.org/api/updates
	Pts int
}

// MessagesForumTopicsTypeID is TL type id of MessagesForumTopics.
const MessagesForumTopicsTypeID = 0x367617d3

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

func ( *MessagesForumTopics) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.OrderByCreateDate == false) {
		return false
	}
	if !(.Count == 0) {
		return false
	}
	if !(.Topics == nil) {
		return false
	}
	if !(.Messages == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}
	if !(.Pts == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesForumTopics from given interface.
func ( *MessagesForumTopics) ( interface {
	() ( bool)
	() ( int)
	() ( []ForumTopicClass)
	() ( []MessageClass)
	() ( []ChatClass)
	() ( []UserClass)
	() ( int)
}) {
	.OrderByCreateDate = .()
	.Count = .()
	.Topics = .()
	.Messages = .()
	.Chats = .()
	.Users = .()
	.Pts = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesForumTopics) () tdp.Type {
	 := tdp.Type{
		Name: "messages.forumTopics",
		ID:   MessagesForumTopicsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "OrderByCreateDate",
			SchemaName: "order_by_create_date",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "Topics",
			SchemaName: "topics",
		},
		{
			Name:       "Messages",
			SchemaName: "messages",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "Pts",
			SchemaName: "pts",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesForumTopics) () {
	if !(.OrderByCreateDate == false) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesForumTopics) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.forumTopics#367617d3 as nil")
	}
	.PutID(MessagesForumTopicsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesForumTopics) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.forumTopics#367617d3 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field flags: %w", )
	}
	.PutInt(.Count)
	.PutVectorHeader(len(.Topics))
	for ,  := range .Topics {
		if  == nil {
			return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field topics element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field topics element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Messages))
	for ,  := range .Messages {
		if  == nil {
			return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field messages element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field messages element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.forumTopics#367617d3: field users element with index %d: %w", , )
		}
	}
	.PutInt(.Pts)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesForumTopics) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.forumTopics#367617d3 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.forumTopics#367617d3: field flags: %w", )
		}
	}
	.OrderByCreateDate = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.forumTopics#367617d3: field count: %w", )
		}
		.Count = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.forumTopics#367617d3: field topics: %w", )
		}

		if  > 0 {
			.Topics = make([]ForumTopicClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeForumTopic()
			if  != nil {
				return fmt.Errorf("unable to decode messages.forumTopics#367617d3: field topics: %w", )
			}
			.Topics = append(.Topics, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.forumTopics#367617d3: field messages: %w", )
		}

		if  > 0 {
			.Messages = make([]MessageClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessage()
			if  != nil {
				return fmt.Errorf("unable to decode messages.forumTopics#367617d3: field messages: %w", )
			}
			.Messages = append(.Messages, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.forumTopics#367617d3: field chats: %w", )
		}

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

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

// SetOrderByCreateDate sets value of OrderByCreateDate conditional field.
func ( *MessagesForumTopics) ( bool) {
	if  {
		.Flags.Set(0)
		.OrderByCreateDate = true
	} else {
		.Flags.Unset(0)
		.OrderByCreateDate = false
	}
}

// GetOrderByCreateDate returns value of OrderByCreateDate conditional field.
func ( *MessagesForumTopics) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetCount returns value of Count field.
func ( *MessagesForumTopics) () ( int) {
	if  == nil {
		return
	}
	return .Count
}

// GetTopics returns value of Topics field.
func ( *MessagesForumTopics) () ( []ForumTopicClass) {
	if  == nil {
		return
	}
	return .Topics
}

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

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

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

// GetPts returns value of Pts field.
func ( *MessagesForumTopics) () ( int) {
	if  == nil {
		return
	}
	return .Pts
}

// MapTopics returns field Topics wrapped in ForumTopicClassArray helper.
func ( *MessagesForumTopics) () ( ForumTopicClassArray) {
	return ForumTopicClassArray(.Topics)
}

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

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

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