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

// Poll represents TL type `poll#966e2dbf`.
// Poll
//
// See https://core.telegram.org/constructor/poll for reference.
type Poll struct {
	// ID of the poll
	ID int64
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the poll is closed and doesn't accept any more answers
	Closed bool
	// Whether cast votes are publicly visible to all users (non-anonymous poll)
	PublicVoters bool
	// Whether multiple options can be chosen as answer
	MultipleChoice bool
	// Whether this is a quiz (with wrong and correct answers, results shown in the return
	// type)
	Quiz bool
	// OpenAnswers field of Poll.
	OpenAnswers bool
	// RevotingDisabled field of Poll.
	RevotingDisabled bool
	// ShuffleAnswers field of Poll.
	ShuffleAnswers bool
	// HideResultsUntilClose field of Poll.
	HideResultsUntilClose bool
	// Creator field of Poll.
	Creator bool
	// SubscribersOnly field of Poll.
	SubscribersOnly bool
	// The question of the poll (only Premium¹ users can use custom emoji entities² here).
	//
	// Links:
	//  1) https://core.telegram.org/api/premium
	//  2) https://core.telegram.org/api/custom-emoji
	Question TextWithEntities
	// The possible answers (2-poll_answers_max¹), vote using messages.sendVote².
	//
	// Links:
	//  1) https://core.telegram.org/api/config#poll-answers-max
	//  2) https://core.telegram.org/method/messages.sendVote
	Answers []PollAnswerClass
	// Amount of time in seconds the poll will be active after creation, 5-600. Can't be used
	// together with close_date.
	//
	// Use SetClosePeriod and GetClosePeriod helpers.
	ClosePeriod int
	// Point in time (Unix timestamp) when the poll will be automatically closed. Must be at
	// least 5 and no more than 600 seconds in the future; can't be used together with
	// close_period.
	//
	// Use SetCloseDate and GetCloseDate helpers.
	CloseDate int
	// CountriesISO2 field of Poll.
	//
	// Use SetCountriesISO2 and GetCountriesISO2 helpers.
	CountriesISO2 []string
	// Hash field of Poll.
	Hash int64
}

// PollTypeID is TL type id of Poll.
const PollTypeID = 0x966e2dbf

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

func ( *Poll) () bool {
	if  == nil {
		return true
	}
	if !(.ID == 0) {
		return false
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Closed == false) {
		return false
	}
	if !(.PublicVoters == false) {
		return false
	}
	if !(.MultipleChoice == false) {
		return false
	}
	if !(.Quiz == false) {
		return false
	}
	if !(.OpenAnswers == false) {
		return false
	}
	if !(.RevotingDisabled == false) {
		return false
	}
	if !(.ShuffleAnswers == false) {
		return false
	}
	if !(.HideResultsUntilClose == false) {
		return false
	}
	if !(.Creator == false) {
		return false
	}
	if !(.SubscribersOnly == false) {
		return false
	}
	if !(.Question.Zero()) {
		return false
	}
	if !(.Answers == nil) {
		return false
	}
	if !(.ClosePeriod == 0) {
		return false
	}
	if !(.CloseDate == 0) {
		return false
	}
	if !(.CountriesISO2 == nil) {
		return false
	}
	if !(.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills Poll from given interface.
func ( *Poll) ( interface {
	() ( int64)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( TextWithEntities)
	() ( []PollAnswerClass)
	() ( int,  bool)
	() ( int,  bool)
	() ( []string,  bool)
	() ( int64)
}) {
	.ID = .()
	.Closed = .()
	.PublicVoters = .()
	.MultipleChoice = .()
	.Quiz = .()
	.OpenAnswers = .()
	.RevotingDisabled = .()
	.ShuffleAnswers = .()
	.HideResultsUntilClose = .()
	.Creator = .()
	.SubscribersOnly = .()
	.Question = .()
	.Answers = .()
	if ,  := .();  {
		.ClosePeriod = 
	}

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

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

	.Hash = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *Poll) () tdp.Type {
	 := tdp.Type{
		Name: "poll",
		ID:   PollTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Closed",
			SchemaName: "closed",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "PublicVoters",
			SchemaName: "public_voters",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "MultipleChoice",
			SchemaName: "multiple_choice",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Quiz",
			SchemaName: "quiz",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "OpenAnswers",
			SchemaName: "open_answers",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "RevotingDisabled",
			SchemaName: "revoting_disabled",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "ShuffleAnswers",
			SchemaName: "shuffle_answers",
			Null:       !.Flags.Has(8),
		},
		{
			Name:       "HideResultsUntilClose",
			SchemaName: "hide_results_until_close",
			Null:       !.Flags.Has(9),
		},
		{
			Name:       "Creator",
			SchemaName: "creator",
			Null:       !.Flags.Has(10),
		},
		{
			Name:       "SubscribersOnly",
			SchemaName: "subscribers_only",
			Null:       !.Flags.Has(11),
		},
		{
			Name:       "Question",
			SchemaName: "question",
		},
		{
			Name:       "Answers",
			SchemaName: "answers",
		},
		{
			Name:       "ClosePeriod",
			SchemaName: "close_period",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "CloseDate",
			SchemaName: "close_date",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "CountriesISO2",
			SchemaName: "countries_iso2",
			Null:       !.Flags.Has(12),
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Poll) () {
	if !(.Closed == false) {
		.Flags.Set(0)
	}
	if !(.PublicVoters == false) {
		.Flags.Set(1)
	}
	if !(.MultipleChoice == false) {
		.Flags.Set(2)
	}
	if !(.Quiz == false) {
		.Flags.Set(3)
	}
	if !(.OpenAnswers == false) {
		.Flags.Set(6)
	}
	if !(.RevotingDisabled == false) {
		.Flags.Set(7)
	}
	if !(.ShuffleAnswers == false) {
		.Flags.Set(8)
	}
	if !(.HideResultsUntilClose == false) {
		.Flags.Set(9)
	}
	if !(.Creator == false) {
		.Flags.Set(10)
	}
	if !(.SubscribersOnly == false) {
		.Flags.Set(11)
	}
	if !(.ClosePeriod == 0) {
		.Flags.Set(4)
	}
	if !(.CloseDate == 0) {
		.Flags.Set(5)
	}
	if !(.CountriesISO2 == nil) {
		.Flags.Set(12)
	}
}

// Encode implements bin.Encoder.
func ( *Poll) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode poll#966e2dbf as nil")
	}
	.PutID(PollTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Poll) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode poll#966e2dbf as nil")
	}
	.SetFlags()
	.PutLong(.ID)
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode poll#966e2dbf: field flags: %w", )
	}
	if  := .Question.Encode();  != nil {
		return fmt.Errorf("unable to encode poll#966e2dbf: field question: %w", )
	}
	.PutVectorHeader(len(.Answers))
	for ,  := range .Answers {
		if  == nil {
			return fmt.Errorf("unable to encode poll#966e2dbf: field answers element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode poll#966e2dbf: field answers element with index %d: %w", , )
		}
	}
	if .Flags.Has(4) {
		.PutInt(.ClosePeriod)
	}
	if .Flags.Has(5) {
		.PutInt(.CloseDate)
	}
	if .Flags.Has(12) {
		.PutVectorHeader(len(.CountriesISO2))
		for ,  := range .CountriesISO2 {
			.PutString()
		}
	}
	.PutLong(.Hash)
	return nil
}

// Decode implements bin.Decoder.
func ( *Poll) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode poll#966e2dbf to nil")
	}
	if  := .ConsumeID(PollTypeID);  != nil {
		return fmt.Errorf("unable to decode poll#966e2dbf: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *Poll) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode poll#966e2dbf to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode poll#966e2dbf: field id: %w", )
		}
		.ID = 
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode poll#966e2dbf: field flags: %w", )
		}
	}
	.Closed = .Flags.Has(0)
	.PublicVoters = .Flags.Has(1)
	.MultipleChoice = .Flags.Has(2)
	.Quiz = .Flags.Has(3)
	.OpenAnswers = .Flags.Has(6)
	.RevotingDisabled = .Flags.Has(7)
	.ShuffleAnswers = .Flags.Has(8)
	.HideResultsUntilClose = .Flags.Has(9)
	.Creator = .Flags.Has(10)
	.SubscribersOnly = .Flags.Has(11)
	{
		if  := .Question.Decode();  != nil {
			return fmt.Errorf("unable to decode poll#966e2dbf: field question: %w", )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode poll#966e2dbf: field answers: %w", )
		}

		if  > 0 {
			.Answers = make([]PollAnswerClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePollAnswer()
			if  != nil {
				return fmt.Errorf("unable to decode poll#966e2dbf: field answers: %w", )
			}
			.Answers = append(.Answers, )
		}
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode poll#966e2dbf: field close_period: %w", )
		}
		.ClosePeriod = 
	}
	if .Flags.Has(5) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode poll#966e2dbf: field close_date: %w", )
		}
		.CloseDate = 
	}
	if .Flags.Has(12) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode poll#966e2dbf: field countries_iso2: %w", )
		}

		if  > 0 {
			.CountriesISO2 = make([]string, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .String()
			if  != nil {
				return fmt.Errorf("unable to decode poll#966e2dbf: field countries_iso2: %w", )
			}
			.CountriesISO2 = append(.CountriesISO2, )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode poll#966e2dbf: field hash: %w", )
		}
		.Hash = 
	}
	return nil
}

// GetID returns value of ID field.
func ( *Poll) () ( int64) {
	if  == nil {
		return
	}
	return .ID
}

// SetClosed sets value of Closed conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(0)
		.Closed = true
	} else {
		.Flags.Unset(0)
		.Closed = false
	}
}

// GetClosed returns value of Closed conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetPublicVoters sets value of PublicVoters conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(1)
		.PublicVoters = true
	} else {
		.Flags.Unset(1)
		.PublicVoters = false
	}
}

// GetPublicVoters returns value of PublicVoters conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetMultipleChoice sets value of MultipleChoice conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(2)
		.MultipleChoice = true
	} else {
		.Flags.Unset(2)
		.MultipleChoice = false
	}
}

// GetMultipleChoice returns value of MultipleChoice conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetQuiz sets value of Quiz conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(3)
		.Quiz = true
	} else {
		.Flags.Unset(3)
		.Quiz = false
	}
}

// GetQuiz returns value of Quiz conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetOpenAnswers sets value of OpenAnswers conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(6)
		.OpenAnswers = true
	} else {
		.Flags.Unset(6)
		.OpenAnswers = false
	}
}

// GetOpenAnswers returns value of OpenAnswers conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(6)
}

// SetRevotingDisabled sets value of RevotingDisabled conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(7)
		.RevotingDisabled = true
	} else {
		.Flags.Unset(7)
		.RevotingDisabled = false
	}
}

// GetRevotingDisabled returns value of RevotingDisabled conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(7)
}

// SetShuffleAnswers sets value of ShuffleAnswers conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(8)
		.ShuffleAnswers = true
	} else {
		.Flags.Unset(8)
		.ShuffleAnswers = false
	}
}

// GetShuffleAnswers returns value of ShuffleAnswers conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(8)
}

// SetHideResultsUntilClose sets value of HideResultsUntilClose conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(9)
		.HideResultsUntilClose = true
	} else {
		.Flags.Unset(9)
		.HideResultsUntilClose = false
	}
}

// GetHideResultsUntilClose returns value of HideResultsUntilClose conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(9)
}

// SetCreator sets value of Creator conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(10)
		.Creator = true
	} else {
		.Flags.Unset(10)
		.Creator = false
	}
}

// GetCreator returns value of Creator conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(10)
}

// SetSubscribersOnly sets value of SubscribersOnly conditional field.
func ( *Poll) ( bool) {
	if  {
		.Flags.Set(11)
		.SubscribersOnly = true
	} else {
		.Flags.Unset(11)
		.SubscribersOnly = false
	}
}

// GetSubscribersOnly returns value of SubscribersOnly conditional field.
func ( *Poll) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(11)
}

// GetQuestion returns value of Question field.
func ( *Poll) () ( TextWithEntities) {
	if  == nil {
		return
	}
	return .Question
}

// GetAnswers returns value of Answers field.
func ( *Poll) () ( []PollAnswerClass) {
	if  == nil {
		return
	}
	return .Answers
}

// SetClosePeriod sets value of ClosePeriod conditional field.
func ( *Poll) ( int) {
	.Flags.Set(4)
	.ClosePeriod = 
}

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

// SetCloseDate sets value of CloseDate conditional field.
func ( *Poll) ( int) {
	.Flags.Set(5)
	.CloseDate = 
}

// GetCloseDate returns value of CloseDate conditional field and
// boolean which is true if field was set.
func ( *Poll) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .CloseDate, true
}

// SetCountriesISO2 sets value of CountriesISO2 conditional field.
func ( *Poll) ( []string) {
	.Flags.Set(12)
	.CountriesISO2 = 
}

// GetCountriesISO2 returns value of CountriesISO2 conditional field and
// boolean which is true if field was set.
func ( *Poll) () ( []string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(12) {
		return , false
	}
	return .CountriesISO2, true
}

// GetHash returns value of Hash field.
func ( *Poll) () ( int64) {
	if  == nil {
		return
	}
	return .Hash
}

// MapAnswers returns field Answers wrapped in PollAnswerClassArray helper.
func ( *Poll) () ( PollAnswerClassArray) {
	return PollAnswerClassArray(.Answers)
}