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

// StoriesAllStoriesNotModified represents TL type `stories.allStoriesNotModified#1158fe3e`.
// The list of active (or active and hidden) stories¹ has not changed.
//
// Links:
//  1. https://core.telegram.org/api/stories#watching-stories
//
// See https://core.telegram.org/constructor/stories.allStoriesNotModified for reference.
type StoriesAllStoriesNotModified struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// State to use to ask for updates
	State string
	// Current stealth mode¹ information
	//
	// Links:
	//  1) https://core.telegram.org/api/stories#stealth-mode
	StealthMode StoriesStealthMode
}

// StoriesAllStoriesNotModifiedTypeID is TL type id of StoriesAllStoriesNotModified.
const StoriesAllStoriesNotModifiedTypeID = 0x1158fe3e

// construct implements constructor of StoriesAllStoriesClass.
func ( StoriesAllStoriesNotModified) () StoriesAllStoriesClass { return & }

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

	_ StoriesAllStoriesClass = &StoriesAllStoriesNotModified{}
)

func ( *StoriesAllStoriesNotModified) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.State == "") {
		return false
	}
	if !(.StealthMode.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills StoriesAllStoriesNotModified from given interface.
func ( *StoriesAllStoriesNotModified) ( interface {
	() ( string)
	() ( StoriesStealthMode)
}) {
	.State = .()
	.StealthMode = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StoriesAllStoriesNotModified) () tdp.Type {
	 := tdp.Type{
		Name: "stories.allStoriesNotModified",
		ID:   StoriesAllStoriesNotModifiedTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "State",
			SchemaName: "state",
		},
		{
			Name:       "StealthMode",
			SchemaName: "stealth_mode",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StoriesAllStoriesNotModified) () {
}

// Encode implements bin.Encoder.
func ( *StoriesAllStoriesNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.allStoriesNotModified#1158fe3e as nil")
	}
	.PutID(StoriesAllStoriesNotModifiedTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StoriesAllStoriesNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.allStoriesNotModified#1158fe3e as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode stories.allStoriesNotModified#1158fe3e: field flags: %w", )
	}
	.PutString(.State)
	if  := .StealthMode.Encode();  != nil {
		return fmt.Errorf("unable to encode stories.allStoriesNotModified#1158fe3e: field stealth_mode: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StoriesAllStoriesNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stories.allStoriesNotModified#1158fe3e to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode stories.allStoriesNotModified#1158fe3e: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode stories.allStoriesNotModified#1158fe3e: field state: %w", )
		}
		.State = 
	}
	{
		if  := .StealthMode.Decode();  != nil {
			return fmt.Errorf("unable to decode stories.allStoriesNotModified#1158fe3e: field stealth_mode: %w", )
		}
	}
	return nil
}

// GetState returns value of State field.
func ( *StoriesAllStoriesNotModified) () ( string) {
	if  == nil {
		return
	}
	return .State
}

// GetStealthMode returns value of StealthMode field.
func ( *StoriesAllStoriesNotModified) () ( StoriesStealthMode) {
	if  == nil {
		return
	}
	return .StealthMode
}

// StoriesAllStories represents TL type `stories.allStories#6efc5e81`.
// Full list of active (or active and hidden) stories¹.
//
// Links:
//  1. https://core.telegram.org/api/stories#watching-stories
//
// See https://core.telegram.org/constructor/stories.allStories for reference.
type StoriesAllStories struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether more results can be fetched as described here »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/stories#watching-stories
	HasMore bool
	// Total number of active (or active and hidden) stories
	Count int
	// State to use for pagination
	State string
	// Stories
	PeerStories []PeerStories
	// Mentioned chats
	Chats []ChatClass
	// Mentioned users
	Users []UserClass
	// Current stealth mode¹ information
	//
	// Links:
	//  1) https://core.telegram.org/api/stories#stealth-mode
	StealthMode StoriesStealthMode
}

// StoriesAllStoriesTypeID is TL type id of StoriesAllStories.
const StoriesAllStoriesTypeID = 0x6efc5e81

// construct implements constructor of StoriesAllStoriesClass.
func ( StoriesAllStories) () StoriesAllStoriesClass { return & }

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

	_ StoriesAllStoriesClass = &StoriesAllStories{}
)

func ( *StoriesAllStories) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.HasMore == false) {
		return false
	}
	if !(.Count == 0) {
		return false
	}
	if !(.State == "") {
		return false
	}
	if !(.PeerStories == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}
	if !(.StealthMode.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills StoriesAllStories from given interface.
func ( *StoriesAllStories) ( interface {
	() ( bool)
	() ( int)
	() ( string)
	() ( []PeerStories)
	() ( []ChatClass)
	() ( []UserClass)
	() ( StoriesStealthMode)
}) {
	.HasMore = .()
	.Count = .()
	.State = .()
	.PeerStories = .()
	.Chats = .()
	.Users = .()
	.StealthMode = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StoriesAllStories) () tdp.Type {
	 := tdp.Type{
		Name: "stories.allStories",
		ID:   StoriesAllStoriesTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "HasMore",
			SchemaName: "has_more",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "State",
			SchemaName: "state",
		},
		{
			Name:       "PeerStories",
			SchemaName: "peer_stories",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "StealthMode",
			SchemaName: "stealth_mode",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *StoriesAllStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.allStories#6efc5e81 as nil")
	}
	.PutID(StoriesAllStoriesTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StoriesAllStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.allStories#6efc5e81 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode stories.allStories#6efc5e81: field flags: %w", )
	}
	.PutInt(.Count)
	.PutString(.State)
	.PutVectorHeader(len(.PeerStories))
	for ,  := range .PeerStories {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stories.allStories#6efc5e81: field peer_stories element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode stories.allStories#6efc5e81: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stories.allStories#6efc5e81: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode stories.allStories#6efc5e81: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stories.allStories#6efc5e81: field users element with index %d: %w", , )
		}
	}
	if  := .StealthMode.Encode();  != nil {
		return fmt.Errorf("unable to encode stories.allStories#6efc5e81: field stealth_mode: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StoriesAllStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stories.allStories#6efc5e81 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode stories.allStories#6efc5e81: field flags: %w", )
		}
	}
	.HasMore = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode stories.allStories#6efc5e81: field count: %w", )
		}
		.Count = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode stories.allStories#6efc5e81: field state: %w", )
		}
		.State = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.allStories#6efc5e81: field peer_stories: %w", )
		}

		if  > 0 {
			.PeerStories = make([]PeerStories, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  PeerStories
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode stories.allStories#6efc5e81: field peer_stories: %w", )
			}
			.PeerStories = append(.PeerStories, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.allStories#6efc5e81: field chats: %w", )
		}

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

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

// SetHasMore sets value of HasMore conditional field.
func ( *StoriesAllStories) ( bool) {
	if  {
		.Flags.Set(0)
		.HasMore = true
	} else {
		.Flags.Unset(0)
		.HasMore = false
	}
}

// GetHasMore returns value of HasMore conditional field.
func ( *StoriesAllStories) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

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

// GetState returns value of State field.
func ( *StoriesAllStories) () ( string) {
	if  == nil {
		return
	}
	return .State
}

// GetPeerStories returns value of PeerStories field.
func ( *StoriesAllStories) () ( []PeerStories) {
	if  == nil {
		return
	}
	return .PeerStories
}

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

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

// GetStealthMode returns value of StealthMode field.
func ( *StoriesAllStories) () ( StoriesStealthMode) {
	if  == nil {
		return
	}
	return .StealthMode
}

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

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

// StoriesAllStoriesClassName is schema name of StoriesAllStoriesClass.
const StoriesAllStoriesClassName = "stories.AllStories"

// StoriesAllStoriesClass represents stories.AllStories generic type.
//
// See https://core.telegram.org/type/stories.AllStories for reference.
//
// Example:
//
//	g, err := tg.DecodeStoriesAllStories(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.StoriesAllStoriesNotModified: // stories.allStoriesNotModified#1158fe3e
//	case *tg.StoriesAllStories: // stories.allStories#6efc5e81
//	default: panic(v)
//	}
type StoriesAllStoriesClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StoriesAllStoriesClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// State to use to ask for updates
	GetState() (value string)

	// Current stealth mode¹ information
	//
	// Links:
	//  1) https://core.telegram.org/api/stories#stealth-mode
	GetStealthMode() (value StoriesStealthMode)

	// AsModified tries to map StoriesAllStoriesClass to StoriesAllStories.
	AsModified() (*StoriesAllStories, bool)
}

// AsModified tries to map StoriesAllStoriesNotModified to StoriesAllStories.
func ( *StoriesAllStoriesNotModified) () (*StoriesAllStories, bool) {
	return nil, false
}

// AsModified tries to map StoriesAllStories to StoriesAllStories.
func ( *StoriesAllStories) () (*StoriesAllStories, bool) {
	return , true
}

// DecodeStoriesAllStories implements binary de-serialization for StoriesAllStoriesClass.
func ( *bin.Buffer) (StoriesAllStoriesClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case StoriesAllStoriesNotModifiedTypeID:
		// Decoding stories.allStoriesNotModified#1158fe3e.
		 := StoriesAllStoriesNotModified{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StoriesAllStoriesClass: %w", )
		}
		return &, nil
	case StoriesAllStoriesTypeID:
		// Decoding stories.allStories#6efc5e81.
		 := StoriesAllStories{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StoriesAllStoriesClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode StoriesAllStoriesClass: %w", bin.NewUnexpectedID())
	}
}

// StoriesAllStories boxes the StoriesAllStoriesClass providing a helper.
type StoriesAllStoriesBox struct {
	AllStories StoriesAllStoriesClass
}

// Decode implements bin.Decoder for StoriesAllStoriesBox.
func ( *StoriesAllStoriesBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode StoriesAllStoriesBox to nil")
	}
	,  := DecodeStoriesAllStories()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.AllStories = 
	return nil
}

// Encode implements bin.Encode for StoriesAllStoriesBox.
func ( *StoriesAllStoriesBox) ( *bin.Buffer) error {
	if  == nil || .AllStories == nil {
		return fmt.Errorf("unable to encode StoriesAllStoriesClass as nil")
	}
	return .AllStories.Encode()
}