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

// PeerStories represents TL type `peerStories#9a35e999`.
// StoriesĀ¹ associated to a peer
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// See https://core.telegram.org/constructor/peerStories for reference.
type PeerStories struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The peer
	Peer PeerClass
	// If set, contains the ID of the maximum read story
	//
	// Use SetMaxReadID and GetMaxReadID helpers.
	MaxReadID int
	// Stories
	Stories []StoryItemClass
}

// PeerStoriesTypeID is TL type id of PeerStories.
const PeerStoriesTypeID = 0x9a35e999

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

func ( *PeerStories) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.MaxReadID == 0) {
		return false
	}
	if !(.Stories == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PeerStories from given interface.
func ( *PeerStories) ( interface {
	() ( PeerClass)
	() ( int,  bool)
	() ( []StoryItemClass)
}) {
	.Peer = .()
	if ,  := .();  {
		.MaxReadID = 
	}

	.Stories = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PeerStories) () tdp.Type {
	 := tdp.Type{
		Name: "peerStories",
		ID:   PeerStoriesTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "MaxReadID",
			SchemaName: "max_read_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Stories",
			SchemaName: "stories",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PeerStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerStories#9a35e999 as nil")
	}
	.PutID(PeerStoriesTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PeerStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerStories#9a35e999 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode peerStories#9a35e999: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode peerStories#9a35e999: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode peerStories#9a35e999: field peer: %w", )
	}
	if .Flags.Has(0) {
		.PutInt(.MaxReadID)
	}
	.PutVectorHeader(len(.Stories))
	for ,  := range .Stories {
		if  == nil {
			return fmt.Errorf("unable to encode peerStories#9a35e999: field stories element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode peerStories#9a35e999: field stories element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PeerStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerStories#9a35e999 to nil")
	}
	if  := .ConsumeID(PeerStoriesTypeID);  != nil {
		return fmt.Errorf("unable to decode peerStories#9a35e999: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PeerStories) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerStories#9a35e999 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode peerStories#9a35e999: field flags: %w", )
		}
	}
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode peerStories#9a35e999: field peer: %w", )
		}
		.Peer = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode peerStories#9a35e999: field max_read_id: %w", )
		}
		.MaxReadID = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode peerStories#9a35e999: field stories: %w", )
		}

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

// GetPeer returns value of Peer field.
func ( *PeerStories) () ( PeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// SetMaxReadID sets value of MaxReadID conditional field.
func ( *PeerStories) ( int) {
	.Flags.Set(0)
	.MaxReadID = 
}

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

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

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