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

// MessagesSearchResultsCalendar represents TL type `messages.searchResultsCalendar#147ee23c`.
// Information about found messages sent on a specific day
//
// See https://core.telegram.org/constructor/messages.searchResultsCalendar for reference.
type MessagesSearchResultsCalendar struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, indicates that the results may be inexact
	Inexact bool
	// Total number of results matching query
	Count int
	// Starting timestamp of attached messages
	MinDate int
	// Ending timestamp of attached messages
	MinMsgID int
	// Indicates the absolute position of messages[0] within the total result set with count
	// count. This is useful, for example, if we need to display a progress/total counter
	// (like photo 134 of 200, for all media in a chat, we could simply use photo
	// ${offset_id_offset} of ${count}.
	//
	// Use SetOffsetIDOffset and GetOffsetIDOffset helpers.
	OffsetIDOffset int
	// Used to split the messages by days: multiple SearchResultsCalendarPeriod¹
	// constructors are returned, each containing information about the first, last and total
	// number of messages matching the filter that were sent on a specific day.  This
	// information can be easily used to split the returned messages by day.
	//
	// Links:
	//  1) https://core.telegram.org/type/SearchResultsCalendarPeriod
	Periods []SearchResultsCalendarPeriod
	// Messages
	Messages []MessageClass
	// Mentioned chats
	Chats []ChatClass
	// Mentioned users
	Users []UserClass
}

// MessagesSearchResultsCalendarTypeID is TL type id of MessagesSearchResultsCalendar.
const MessagesSearchResultsCalendarTypeID = 0x147ee23c

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

func ( *MessagesSearchResultsCalendar) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Inexact == false) {
		return false
	}
	if !(.Count == 0) {
		return false
	}
	if !(.MinDate == 0) {
		return false
	}
	if !(.MinMsgID == 0) {
		return false
	}
	if !(.OffsetIDOffset == 0) {
		return false
	}
	if !(.Periods == nil) {
		return false
	}
	if !(.Messages == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSearchResultsCalendar from given interface.
func ( *MessagesSearchResultsCalendar) ( interface {
	() ( bool)
	() ( int)
	() ( int)
	() ( int)
	() ( int,  bool)
	() ( []SearchResultsCalendarPeriod)
	() ( []MessageClass)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Inexact = .()
	.Count = .()
	.MinDate = .()
	.MinMsgID = .()
	if ,  := .();  {
		.OffsetIDOffset = 
	}

	.Periods = .()
	.Messages = .()
	.Chats = .()
	.Users = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesSearchResultsCalendar) () tdp.Type {
	 := tdp.Type{
		Name: "messages.searchResultsCalendar",
		ID:   MessagesSearchResultsCalendarTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Inexact",
			SchemaName: "inexact",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "MinDate",
			SchemaName: "min_date",
		},
		{
			Name:       "MinMsgID",
			SchemaName: "min_msg_id",
		},
		{
			Name:       "OffsetIDOffset",
			SchemaName: "offset_id_offset",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Periods",
			SchemaName: "periods",
		},
		{
			Name:       "Messages",
			SchemaName: "messages",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesSearchResultsCalendar) () {
	if !(.Inexact == false) {
		.Flags.Set(0)
	}
	if !(.OffsetIDOffset == 0) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesSearchResultsCalendar) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.searchResultsCalendar#147ee23c as nil")
	}
	.PutID(MessagesSearchResultsCalendarTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesSearchResultsCalendar) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.searchResultsCalendar#147ee23c as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.searchResultsCalendar#147ee23c: field flags: %w", )
	}
	.PutInt(.Count)
	.PutInt(.MinDate)
	.PutInt(.MinMsgID)
	if .Flags.Has(1) {
		.PutInt(.OffsetIDOffset)
	}
	.PutVectorHeader(len(.Periods))
	for ,  := range .Periods {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.searchResultsCalendar#147ee23c: field periods element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Messages))
	for ,  := range .Messages {
		if  == nil {
			return fmt.Errorf("unable to encode messages.searchResultsCalendar#147ee23c: field messages element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.searchResultsCalendar#147ee23c: field messages element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode messages.searchResultsCalendar#147ee23c: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.searchResultsCalendar#147ee23c: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode messages.searchResultsCalendar#147ee23c: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.searchResultsCalendar#147ee23c: field users element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesSearchResultsCalendar) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.searchResultsCalendar#147ee23c to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.searchResultsCalendar#147ee23c: field flags: %w", )
		}
	}
	.Inexact = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchResultsCalendar#147ee23c: field count: %w", )
		}
		.Count = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchResultsCalendar#147ee23c: field min_date: %w", )
		}
		.MinDate = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchResultsCalendar#147ee23c: field min_msg_id: %w", )
		}
		.MinMsgID = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchResultsCalendar#147ee23c: field offset_id_offset: %w", )
		}
		.OffsetIDOffset = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchResultsCalendar#147ee23c: field periods: %w", )
		}

		if  > 0 {
			.Periods = make([]SearchResultsCalendarPeriod, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  SearchResultsCalendarPeriod
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode messages.searchResultsCalendar#147ee23c: field periods: %w", )
			}
			.Periods = append(.Periods, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchResultsCalendar#147ee23c: field messages: %w", )
		}

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

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

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

// SetInexact sets value of Inexact conditional field.
func ( *MessagesSearchResultsCalendar) ( bool) {
	if  {
		.Flags.Set(0)
		.Inexact = true
	} else {
		.Flags.Unset(0)
		.Inexact = false
	}
}

// GetInexact returns value of Inexact conditional field.
func ( *MessagesSearchResultsCalendar) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

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

// GetMinDate returns value of MinDate field.
func ( *MessagesSearchResultsCalendar) () ( int) {
	if  == nil {
		return
	}
	return .MinDate
}

// GetMinMsgID returns value of MinMsgID field.
func ( *MessagesSearchResultsCalendar) () ( int) {
	if  == nil {
		return
	}
	return .MinMsgID
}

// SetOffsetIDOffset sets value of OffsetIDOffset conditional field.
func ( *MessagesSearchResultsCalendar) ( int) {
	.Flags.Set(1)
	.OffsetIDOffset = 
}

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

// GetPeriods returns value of Periods field.
func ( *MessagesSearchResultsCalendar) () ( []SearchResultsCalendarPeriod) {
	if  == nil {
		return
	}
	return .Periods
}

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

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

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

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

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

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