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

// MessagesVotesList represents TL type `messages.votesList#4899484e`.
// How users voted in a poll
//
// See https://core.telegram.org/constructor/messages.votesList for reference.
type MessagesVotesList struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Total number of votes for all options (or only for the chosen option, if provided to
	// messages.getPollVotesĀ¹)
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.getPollVotes
	Count int
	// Vote info for each user
	Votes []MessagePeerVoteClass
	// Mentioned chats
	Chats []ChatClass
	// Info about users that voted in the poll
	Users []UserClass
	// Offset to use with the next messages.getPollVotesĀ¹ request, empty string if no more
	// results are available.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.getPollVotes
	//
	// Use SetNextOffset and GetNextOffset helpers.
	NextOffset string
}

// MessagesVotesListTypeID is TL type id of MessagesVotesList.
const MessagesVotesListTypeID = 0x4899484e

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

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

	return true
}

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

// FillFrom fills MessagesVotesList from given interface.
func ( *MessagesVotesList) ( interface {
	() ( int)
	() ( []MessagePeerVoteClass)
	() ( []ChatClass)
	() ( []UserClass)
	() ( string,  bool)
}) {
	.Count = .()
	.Votes = .()
	.Chats = .()
	.Users = .()
	if ,  := .();  {
		.NextOffset = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*MessagesVotesList) () string {
	return "messages.votesList"
}

// TypeInfo returns info about TL type.
func ( *MessagesVotesList) () tdp.Type {
	 := tdp.Type{
		Name: "messages.votesList",
		ID:   MessagesVotesListTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "Votes",
			SchemaName: "votes",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "NextOffset",
			SchemaName: "next_offset",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *MessagesVotesList) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.votesList#4899484e as nil")
	}
	.PutID(MessagesVotesListTypeID)
	return .EncodeBare()
}

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

// Decode implements bin.Decoder.
func ( *MessagesVotesList) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.votesList#4899484e to nil")
	}
	if  := .ConsumeID(MessagesVotesListTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.votesList#4899484e: %w", )
	}
	return .DecodeBare()
}

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

		if  > 0 {
			.Votes = make([]MessagePeerVoteClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessagePeerVote()
			if  != nil {
				return fmt.Errorf("unable to decode messages.votesList#4899484e: field votes: %w", )
			}
			.Votes = append(.Votes, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.votesList#4899484e: field chats: %w", )
		}

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

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode messages.votesList#4899484e: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.votesList#4899484e: field next_offset: %w", )
		}
		.NextOffset = 
	}
	return nil
}

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

// GetVotes returns value of Votes field.
func ( *MessagesVotesList) () ( []MessagePeerVoteClass) {
	if  == nil {
		return
	}
	return .Votes
}

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

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

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

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

// MapVotes returns field Votes wrapped in MessagePeerVoteClassArray helper.
func ( *MessagesVotesList) () ( MessagePeerVoteClassArray) {
	return MessagePeerVoteClassArray(.Votes)
}

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

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