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

// PollResults represents TL type `pollResults#7adf2420`.
// Results of poll
//
// See https://core.telegram.org/constructor/pollResults for reference.
type PollResults struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Similar to min¹ objects, used for poll constructors that are the same for all users
	// so they don't have the option chosen by the current user (you can use messages
	// getPollResults² to get the full poll results).
	//
	// Links:
	//  1) https://core.telegram.org/api/min
	//  2) https://core.telegram.org/method/messages.getPollResults
	Min bool
	// Poll results
	//
	// Use SetResults and GetResults helpers.
	Results []PollAnswerVoters
	// Total number of people that voted in the poll
	//
	// Use SetTotalVoters and GetTotalVoters helpers.
	TotalVoters int
	// IDs of the last users that recently voted in the poll
	//
	// Use SetRecentVoters and GetRecentVoters helpers.
	RecentVoters []PeerClass
	// Explanation of quiz solution
	//
	// Use SetSolution and GetSolution helpers.
	Solution string
	// Message entities for styled text in quiz solution¹
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//
	// Use SetSolutionEntities and GetSolutionEntities helpers.
	SolutionEntities []MessageEntityClass
}

// PollResultsTypeID is TL type id of PollResults.
const PollResultsTypeID = 0x7adf2420

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

func ( *PollResults) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Min == false) {
		return false
	}
	if !(.Results == nil) {
		return false
	}
	if !(.TotalVoters == 0) {
		return false
	}
	if !(.RecentVoters == nil) {
		return false
	}
	if !(.Solution == "") {
		return false
	}
	if !(.SolutionEntities == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PollResults from given interface.
func ( *PollResults) ( interface {
	() ( bool)
	() ( []PollAnswerVoters,  bool)
	() ( int,  bool)
	() ( []PeerClass,  bool)
	() ( string,  bool)
	() ( []MessageEntityClass,  bool)
}) {
	.Min = .()
	if ,  := .();  {
		.Results = 
	}

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

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *PollResults) () tdp.Type {
	 := tdp.Type{
		Name: "pollResults",
		ID:   PollResultsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Min",
			SchemaName: "min",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Results",
			SchemaName: "results",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "TotalVoters",
			SchemaName: "total_voters",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "RecentVoters",
			SchemaName: "recent_voters",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Solution",
			SchemaName: "solution",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "SolutionEntities",
			SchemaName: "solution_entities",
			Null:       !.Flags.Has(4),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PollResults) () {
	if !(.Min == false) {
		.Flags.Set(0)
	}
	if !(.Results == nil) {
		.Flags.Set(1)
	}
	if !(.TotalVoters == 0) {
		.Flags.Set(2)
	}
	if !(.RecentVoters == nil) {
		.Flags.Set(3)
	}
	if !(.Solution == "") {
		.Flags.Set(4)
	}
	if !(.SolutionEntities == nil) {
		.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func ( *PollResults) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pollResults#7adf2420 as nil")
	}
	.PutID(PollResultsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PollResults) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pollResults#7adf2420 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode pollResults#7adf2420: field flags: %w", )
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.Results))
		for ,  := range .Results {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode pollResults#7adf2420: field results element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(2) {
		.PutInt(.TotalVoters)
	}
	if .Flags.Has(3) {
		.PutVectorHeader(len(.RecentVoters))
		for ,  := range .RecentVoters {
			if  == nil {
				return fmt.Errorf("unable to encode pollResults#7adf2420: field recent_voters element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode pollResults#7adf2420: field recent_voters element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(4) {
		.PutString(.Solution)
	}
	if .Flags.Has(4) {
		.PutVectorHeader(len(.SolutionEntities))
		for ,  := range .SolutionEntities {
			if  == nil {
				return fmt.Errorf("unable to encode pollResults#7adf2420: field solution_entities element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode pollResults#7adf2420: field solution_entities element with index %d: %w", , )
			}
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PollResults) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pollResults#7adf2420 to nil")
	}
	if  := .ConsumeID(PollResultsTypeID);  != nil {
		return fmt.Errorf("unable to decode pollResults#7adf2420: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PollResults) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pollResults#7adf2420 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode pollResults#7adf2420: field flags: %w", )
		}
	}
	.Min = .Flags.Has(0)
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode pollResults#7adf2420: field results: %w", )
		}

		if  > 0 {
			.Results = make([]PollAnswerVoters, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  PollAnswerVoters
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode pollResults#7adf2420: field results: %w", )
			}
			.Results = append(.Results, )
		}
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode pollResults#7adf2420: field total_voters: %w", )
		}
		.TotalVoters = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode pollResults#7adf2420: field recent_voters: %w", )
		}

		if  > 0 {
			.RecentVoters = make([]PeerClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePeer()
			if  != nil {
				return fmt.Errorf("unable to decode pollResults#7adf2420: field recent_voters: %w", )
			}
			.RecentVoters = append(.RecentVoters, )
		}
	}
	if .Flags.Has(4) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode pollResults#7adf2420: field solution: %w", )
		}
		.Solution = 
	}
	if .Flags.Has(4) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode pollResults#7adf2420: field solution_entities: %w", )
		}

		if  > 0 {
			.SolutionEntities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode pollResults#7adf2420: field solution_entities: %w", )
			}
			.SolutionEntities = append(.SolutionEntities, )
		}
	}
	return nil
}

// SetMin sets value of Min conditional field.
func ( *PollResults) ( bool) {
	if  {
		.Flags.Set(0)
		.Min = true
	} else {
		.Flags.Unset(0)
		.Min = false
	}
}

// GetMin returns value of Min conditional field.
func ( *PollResults) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetResults sets value of Results conditional field.
func ( *PollResults) ( []PollAnswerVoters) {
	.Flags.Set(1)
	.Results = 
}

// GetResults returns value of Results conditional field and
// boolean which is true if field was set.
func ( *PollResults) () ( []PollAnswerVoters,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Results, true
}

// SetTotalVoters sets value of TotalVoters conditional field.
func ( *PollResults) ( int) {
	.Flags.Set(2)
	.TotalVoters = 
}

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

// SetRecentVoters sets value of RecentVoters conditional field.
func ( *PollResults) ( []PeerClass) {
	.Flags.Set(3)
	.RecentVoters = 
}

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

// SetSolution sets value of Solution conditional field.
func ( *PollResults) ( string) {
	.Flags.Set(4)
	.Solution = 
}

// GetSolution returns value of Solution conditional field and
// boolean which is true if field was set.
func ( *PollResults) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .Solution, true
}

// SetSolutionEntities sets value of SolutionEntities conditional field.
func ( *PollResults) ( []MessageEntityClass) {
	.Flags.Set(4)
	.SolutionEntities = 
}

// GetSolutionEntities returns value of SolutionEntities conditional field and
// boolean which is true if field was set.
func ( *PollResults) () ( []MessageEntityClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .SolutionEntities, true
}

// MapRecentVoters returns field RecentVoters wrapped in PeerClassArray helper.
func ( *PollResults) () ( PeerClassArray,  bool) {
	if !.Flags.Has(3) {
		return , false
	}
	return PeerClassArray(.RecentVoters), true
}

// MapSolutionEntities returns field SolutionEntities wrapped in MessageEntityClassArray helper.
func ( *PollResults) () ( MessageEntityClassArray,  bool) {
	if !.Flags.Has(4) {
		return , false
	}
	return MessageEntityClassArray(.SolutionEntities), true
}