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

// StoryViews represents TL type `storyViews#8d595cd6`.
// Aggregated view and reaction information of a story¹.
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// See https://core.telegram.org/constructor/storyViews for reference.
type StoryViews 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 viewers list is currently viewable, and was not yet deleted
	// because the story has expired while the user didn't have a Premium¹ account.
	//
	// Links:
	//  1) https://core.telegram.org/api/premium
	HasViewers bool
	// View counter of the story
	ViewsCount int
	// Forward counter of the story
	//
	// Use SetForwardsCount and GetForwardsCount helpers.
	ForwardsCount int
	// All reactions sent to this story
	//
	// Use SetReactions and GetReactions helpers.
	Reactions []ReactionCount
	// Number of reactions added to the story
	//
	// Use SetReactionsCount and GetReactionsCount helpers.
	ReactionsCount int
	// User IDs of some recent viewers of the story
	//
	// Use SetRecentViewers and GetRecentViewers helpers.
	RecentViewers []int64
}

// StoryViewsTypeID is TL type id of StoryViews.
const StoryViewsTypeID = 0x8d595cd6

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

func ( *StoryViews) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.HasViewers == false) {
		return false
	}
	if !(.ViewsCount == 0) {
		return false
	}
	if !(.ForwardsCount == 0) {
		return false
	}
	if !(.Reactions == nil) {
		return false
	}
	if !(.ReactionsCount == 0) {
		return false
	}
	if !(.RecentViewers == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StoryViews from given interface.
func ( *StoryViews) ( interface {
	() ( bool)
	() ( int)
	() ( int,  bool)
	() ( []ReactionCount,  bool)
	() ( int,  bool)
	() ( []int64,  bool)
}) {
	.HasViewers = .()
	.ViewsCount = .()
	if ,  := .();  {
		.ForwardsCount = 
	}

	if ,  := .();  {
		.Reactions = 
	}

	if ,  := .();  {
		.ReactionsCount = 
	}

	if ,  := .();  {
		.RecentViewers = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *StoryViews) () tdp.Type {
	 := tdp.Type{
		Name: "storyViews",
		ID:   StoryViewsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "HasViewers",
			SchemaName: "has_viewers",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ViewsCount",
			SchemaName: "views_count",
		},
		{
			Name:       "ForwardsCount",
			SchemaName: "forwards_count",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Reactions",
			SchemaName: "reactions",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "ReactionsCount",
			SchemaName: "reactions_count",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "RecentViewers",
			SchemaName: "recent_viewers",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StoryViews) () {
	if !(.HasViewers == false) {
		.Flags.Set(1)
	}
	if !(.ForwardsCount == 0) {
		.Flags.Set(2)
	}
	if !(.Reactions == nil) {
		.Flags.Set(3)
	}
	if !(.ReactionsCount == 0) {
		.Flags.Set(4)
	}
	if !(.RecentViewers == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *StoryViews) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode storyViews#8d595cd6 as nil")
	}
	.PutID(StoryViewsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StoryViews) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode storyViews#8d595cd6 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode storyViews#8d595cd6: field flags: %w", )
	}
	.PutInt(.ViewsCount)
	if .Flags.Has(2) {
		.PutInt(.ForwardsCount)
	}
	if .Flags.Has(3) {
		.PutVectorHeader(len(.Reactions))
		for ,  := range .Reactions {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode storyViews#8d595cd6: field reactions element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(4) {
		.PutInt(.ReactionsCount)
	}
	if .Flags.Has(0) {
		.PutVectorHeader(len(.RecentViewers))
		for ,  := range .RecentViewers {
			.PutLong()
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *StoryViews) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode storyViews#8d595cd6 to nil")
	}
	if  := .ConsumeID(StoryViewsTypeID);  != nil {
		return fmt.Errorf("unable to decode storyViews#8d595cd6: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *StoryViews) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode storyViews#8d595cd6 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode storyViews#8d595cd6: field flags: %w", )
		}
	}
	.HasViewers = .Flags.Has(1)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode storyViews#8d595cd6: field views_count: %w", )
		}
		.ViewsCount = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode storyViews#8d595cd6: field forwards_count: %w", )
		}
		.ForwardsCount = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode storyViews#8d595cd6: field reactions: %w", )
		}

		if  > 0 {
			.Reactions = make([]ReactionCount, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  ReactionCount
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode storyViews#8d595cd6: field reactions: %w", )
			}
			.Reactions = append(.Reactions, )
		}
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode storyViews#8d595cd6: field reactions_count: %w", )
		}
		.ReactionsCount = 
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode storyViews#8d595cd6: field recent_viewers: %w", )
		}

		if  > 0 {
			.RecentViewers = make([]int64, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .Long()
			if  != nil {
				return fmt.Errorf("unable to decode storyViews#8d595cd6: field recent_viewers: %w", )
			}
			.RecentViewers = append(.RecentViewers, )
		}
	}
	return nil
}

// SetHasViewers sets value of HasViewers conditional field.
func ( *StoryViews) ( bool) {
	if  {
		.Flags.Set(1)
		.HasViewers = true
	} else {
		.Flags.Unset(1)
		.HasViewers = false
	}
}

// GetHasViewers returns value of HasViewers conditional field.
func ( *StoryViews) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetViewsCount returns value of ViewsCount field.
func ( *StoryViews) () ( int) {
	if  == nil {
		return
	}
	return .ViewsCount
}

// SetForwardsCount sets value of ForwardsCount conditional field.
func ( *StoryViews) ( int) {
	.Flags.Set(2)
	.ForwardsCount = 
}

// GetForwardsCount returns value of ForwardsCount conditional field and
// boolean which is true if field was set.
func ( *StoryViews) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .ForwardsCount, true
}

// SetReactions sets value of Reactions conditional field.
func ( *StoryViews) ( []ReactionCount) {
	.Flags.Set(3)
	.Reactions = 
}

// GetReactions returns value of Reactions conditional field and
// boolean which is true if field was set.
func ( *StoryViews) () ( []ReactionCount,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Reactions, true
}

// SetReactionsCount sets value of ReactionsCount conditional field.
func ( *StoryViews) ( int) {
	.Flags.Set(4)
	.ReactionsCount = 
}

// GetReactionsCount returns value of ReactionsCount conditional field and
// boolean which is true if field was set.
func ( *StoryViews) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .ReactionsCount, true
}

// SetRecentViewers sets value of RecentViewers conditional field.
func ( *StoryViews) ( []int64) {
	.Flags.Set(0)
	.RecentViewers = 
}

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