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

// StoriesStories represents TL type `stories.stories#63c3dd0a`.
// List of stories¹
//
// Links:
//  1. https://core.telegram.org/api/stories#pinned-or-archived-stories
//
// See https://core.telegram.org/constructor/stories.stories for reference.
type StoriesStories struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Total number of stories that can be fetched
	Count int
	// Stories
	Stories []StoryItemClass
	// IDs of pinned stories.
	//
	// Use SetPinnedToTop and GetPinnedToTop helpers.
	PinnedToTop []int
	// Mentioned chats
	Chats []ChatClass
	// Mentioned users
	Users []UserClass
}

// StoriesStoriesTypeID is TL type id of StoriesStories.
const StoriesStoriesTypeID = 0x63c3dd0a

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

func ( *StoriesStories) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Count == 0) {
		return false
	}
	if !(.Stories == nil) {
		return false
	}
	if !(.PinnedToTop == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StoriesStories from given interface.
func ( *StoriesStories) ( interface {
	() ( int)
	() ( []StoryItemClass)
	() ( []int,  bool)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Count = .()
	.Stories = .()
	if ,  := .();  {
		.PinnedToTop = 
	}

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

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

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

// TypeInfo returns info about TL type.
func ( *StoriesStories) () tdp.Type {
	 := tdp.Type{
		Name: "stories.stories",
		ID:   StoriesStoriesTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "Stories",
			SchemaName: "stories",
		},
		{
			Name:       "PinnedToTop",
			SchemaName: "pinned_to_top",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StoriesStories) () {
	if !(.PinnedToTop == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *StoriesStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.stories#63c3dd0a as nil")
	}
	.PutID(StoriesStoriesTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StoriesStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.stories#63c3dd0a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode stories.stories#63c3dd0a: field flags: %w", )
	}
	.PutInt(.Count)
	.PutVectorHeader(len(.Stories))
	for ,  := range .Stories {
		if  == nil {
			return fmt.Errorf("unable to encode stories.stories#63c3dd0a: field stories element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stories.stories#63c3dd0a: field stories element with index %d: %w", , )
		}
	}
	if .Flags.Has(0) {
		.PutVectorHeader(len(.PinnedToTop))
		for ,  := range .PinnedToTop {
			.PutInt()
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode stories.stories#63c3dd0a: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stories.stories#63c3dd0a: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode stories.stories#63c3dd0a: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stories.stories#63c3dd0a: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *StoriesStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stories.stories#63c3dd0a to nil")
	}
	if  := .ConsumeID(StoriesStoriesTypeID);  != nil {
		return fmt.Errorf("unable to decode stories.stories#63c3dd0a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *StoriesStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stories.stories#63c3dd0a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode stories.stories#63c3dd0a: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode stories.stories#63c3dd0a: field count: %w", )
		}
		.Count = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.stories#63c3dd0a: field stories: %w", )
		}

		if  > 0 {
			.Stories = make([]StoryItemClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeStoryItem()
			if  != nil {
				return fmt.Errorf("unable to decode stories.stories#63c3dd0a: field stories: %w", )
			}
			.Stories = append(.Stories, )
		}
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.stories#63c3dd0a: field pinned_to_top: %w", )
		}

		if  > 0 {
			.PinnedToTop = make([]int, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .Int()
			if  != nil {
				return fmt.Errorf("unable to decode stories.stories#63c3dd0a: field pinned_to_top: %w", )
			}
			.PinnedToTop = append(.PinnedToTop, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.stories#63c3dd0a: field chats: %w", )
		}

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

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

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

// GetStories returns value of Stories field.
func ( *StoriesStories) () ( []StoryItemClass) {
	if  == nil {
		return
	}
	return .Stories
}

// SetPinnedToTop sets value of PinnedToTop conditional field.
func ( *StoriesStories) ( []int) {
	.Flags.Set(0)
	.PinnedToTop = 
}

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

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

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

// MapStories returns field Stories wrapped in StoryItemClassArray helper.
func ( *StoriesStories) () ( StoryItemClassArray) {
	return StoryItemClassArray(.Stories)
}

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

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