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

// StatsPublicForwards represents TL type `stats.publicForwards#93037e20`.
// Contains info about the forwards of a story¹ as a message to public chats and reposts
// by public channels.
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// See https://core.telegram.org/constructor/stats.publicForwards for reference.
type StatsPublicForwards struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Total number of results
	Count int
	// Info about the forwards of a story.
	Forwards []PublicForwardClass
	// Offset used for pagination¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	//
	// Use SetNextOffset and GetNextOffset helpers.
	NextOffset string
	// Mentioned chats
	Chats []ChatClass
	// Mentioned users
	Users []UserClass
}

// StatsPublicForwardsTypeID is TL type id of StatsPublicForwards.
const StatsPublicForwardsTypeID = 0x93037e20

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

func ( *StatsPublicForwards) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Count == 0) {
		return false
	}
	if !(.Forwards == nil) {
		return false
	}
	if !(.NextOffset == "") {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StatsPublicForwards from given interface.
func ( *StatsPublicForwards) ( interface {
	() ( int)
	() ( []PublicForwardClass)
	() ( string,  bool)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Count = .()
	.Forwards = .()
	if ,  := .();  {
		.NextOffset = 
	}

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

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

// TypeName returns name of type in TL schema.
func (*StatsPublicForwards) () string {
	return "stats.publicForwards"
}

// TypeInfo returns info about TL type.
func ( *StatsPublicForwards) () tdp.Type {
	 := tdp.Type{
		Name: "stats.publicForwards",
		ID:   StatsPublicForwardsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "Forwards",
			SchemaName: "forwards",
		},
		{
			Name:       "NextOffset",
			SchemaName: "next_offset",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *StatsPublicForwards) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stats.publicForwards#93037e20 as nil")
	}
	.PutID(StatsPublicForwardsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StatsPublicForwards) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stats.publicForwards#93037e20 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode stats.publicForwards#93037e20: field flags: %w", )
	}
	.PutInt(.Count)
	.PutVectorHeader(len(.Forwards))
	for ,  := range .Forwards {
		if  == nil {
			return fmt.Errorf("unable to encode stats.publicForwards#93037e20: field forwards element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stats.publicForwards#93037e20: field forwards element with index %d: %w", , )
		}
	}
	if .Flags.Has(0) {
		.PutString(.NextOffset)
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode stats.publicForwards#93037e20: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stats.publicForwards#93037e20: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode stats.publicForwards#93037e20: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode stats.publicForwards#93037e20: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *StatsPublicForwards) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stats.publicForwards#93037e20 to nil")
	}
	if  := .ConsumeID(StatsPublicForwardsTypeID);  != nil {
		return fmt.Errorf("unable to decode stats.publicForwards#93037e20: %w", )
	}
	return .DecodeBare()
}

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

		if  > 0 {
			.Forwards = make([]PublicForwardClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePublicForward()
			if  != nil {
				return fmt.Errorf("unable to decode stats.publicForwards#93037e20: field forwards: %w", )
			}
			.Forwards = append(.Forwards, )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode stats.publicForwards#93037e20: field next_offset: %w", )
		}
		.NextOffset = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stats.publicForwards#93037e20: field chats: %w", )
		}

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

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

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

// GetForwards returns value of Forwards field.
func ( *StatsPublicForwards) () ( []PublicForwardClass) {
	if  == nil {
		return
	}
	return .Forwards
}

// SetNextOffset sets value of NextOffset conditional field.
func ( *StatsPublicForwards) ( string) {
	.Flags.Set(0)
	.NextOffset = 
}

// GetNextOffset returns value of NextOffset conditional field and
// boolean which is true if field was set.
func ( *StatsPublicForwards) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .NextOffset, true
}

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

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

// MapForwards returns field Forwards wrapped in PublicForwardClassArray helper.
func ( *StatsPublicForwards) () ( PublicForwardClassArray) {
	return PublicForwardClassArray(.Forwards)
}

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

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