// 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#86e18161`.
// 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
	// The question of the poll
	Question string
	// The possible answers, vote using messages.sendVoteĀ¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.sendVote
	Answers []PollAnswer
	// 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
}

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

// 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 !(.Question == "") {
		return false
	}
	if !(.Answers == nil) {
		return false
	}
	if !(.ClosePeriod == 0) {
		return false
	}
	if !(.CloseDate == 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)
	() ( string)
	() ( []PollAnswer)
	() ( int,  bool)
	() ( int,  bool)
}) {
	.ID = .()
	.Closed = .()
	.PublicVoters = .()
	.MultipleChoice = .()
	.Quiz = .()
	.Question = .()
	.Answers = .()
	if ,  := .();  {
		.ClosePeriod = 
	}

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

}

// 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:       "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),
		},
	}
	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 !(.ClosePeriod == 0) {
		.Flags.Set(4)
	}
	if !(.CloseDate == 0) {
		.Flags.Set(5)
	}
}

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

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

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

// DecodeBare implements bin.BareDecoder.
func ( *Poll) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode poll#86e18161 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode poll#86e18161: field id: %w", )
		}
		.ID = 
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode poll#86e18161: field flags: %w", )
		}
	}
	.Closed = .Flags.Has(0)
	.PublicVoters = .Flags.Has(1)
	.MultipleChoice = .Flags.Has(2)
	.Quiz = .Flags.Has(3)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode poll#86e18161: field question: %w", )
		}
		.Question = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode poll#86e18161: field answers: %w", )
		}

		if  > 0 {
			.Answers = make([]PollAnswer, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  PollAnswer
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode poll#86e18161: field answers: %w", )
			}
			.Answers = append(.Answers, )
		}
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode poll#86e18161: field close_period: %w", )
		}
		.ClosePeriod = 
	}
	if .Flags.Has(5) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode poll#86e18161: field close_date: %w", )
		}
		.CloseDate = 
	}
	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)
}

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

// GetAnswers returns value of Answers field.
func ( *Poll) () ( []PollAnswer) {
	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
}