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

// PollAnswerVoters represents TL type `pollAnswerVoters#3645230a`.
// A poll answer, and how users voted on it
//
// See https://core.telegram.org/constructor/pollAnswerVoters for reference.
type PollAnswerVoters struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether we have chosen this answer
	Chosen bool
	// For quizzes, whether the option we have chosen is correct
	Correct bool
	// The param that has to be passed to messages.sendVote¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.sendVote
	Option []byte
	// How many users voted for this option
	//
	// Use SetVoters and GetVoters helpers.
	Voters int
	// RecentVoters field of PollAnswerVoters.
	//
	// Use SetRecentVoters and GetRecentVoters helpers.
	RecentVoters []PeerClass
}

// PollAnswerVotersTypeID is TL type id of PollAnswerVoters.
const PollAnswerVotersTypeID = 0x3645230a

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

func ( *PollAnswerVoters) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Chosen == false) {
		return false
	}
	if !(.Correct == false) {
		return false
	}
	if !(.Option == nil) {
		return false
	}
	if !(.Voters == 0) {
		return false
	}
	if !(.RecentVoters == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PollAnswerVoters from given interface.
func ( *PollAnswerVoters) ( interface {
	() ( bool)
	() ( bool)
	() ( []byte)
	() ( int,  bool)
	() ( []PeerClass,  bool)
}) {
	.Chosen = .()
	.Correct = .()
	.Option = .()
	if ,  := .();  {
		.Voters = 
	}

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

}

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

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

// TypeInfo returns info about TL type.
func ( *PollAnswerVoters) () tdp.Type {
	 := tdp.Type{
		Name: "pollAnswerVoters",
		ID:   PollAnswerVotersTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Chosen",
			SchemaName: "chosen",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Correct",
			SchemaName: "correct",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Option",
			SchemaName: "option",
		},
		{
			Name:       "Voters",
			SchemaName: "voters",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "RecentVoters",
			SchemaName: "recent_voters",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PollAnswerVoters) () {
	if !(.Chosen == false) {
		.Flags.Set(0)
	}
	if !(.Correct == false) {
		.Flags.Set(1)
	}
	if !(.Voters == 0) {
		.Flags.Set(2)
	}
	if !(.RecentVoters == nil) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *PollAnswerVoters) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pollAnswerVoters#3645230a as nil")
	}
	.PutID(PollAnswerVotersTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PollAnswerVoters) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pollAnswerVoters#3645230a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode pollAnswerVoters#3645230a: field flags: %w", )
	}
	.PutBytes(.Option)
	if .Flags.Has(2) {
		.PutInt(.Voters)
	}
	if .Flags.Has(2) {
		.PutVectorHeader(len(.RecentVoters))
		for ,  := range .RecentVoters {
			if  == nil {
				return fmt.Errorf("unable to encode pollAnswerVoters#3645230a: field recent_voters element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode pollAnswerVoters#3645230a: field recent_voters element with index %d: %w", , )
			}
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PollAnswerVoters) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pollAnswerVoters#3645230a to nil")
	}
	if  := .ConsumeID(PollAnswerVotersTypeID);  != nil {
		return fmt.Errorf("unable to decode pollAnswerVoters#3645230a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PollAnswerVoters) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pollAnswerVoters#3645230a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode pollAnswerVoters#3645230a: field flags: %w", )
		}
	}
	.Chosen = .Flags.Has(0)
	.Correct = .Flags.Has(1)
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode pollAnswerVoters#3645230a: field option: %w", )
		}
		.Option = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode pollAnswerVoters#3645230a: field voters: %w", )
		}
		.Voters = 
	}
	if .Flags.Has(2) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode pollAnswerVoters#3645230a: field recent_voters: %w", )
		}

		if  > 0 {
			.RecentVoters = make([]PeerClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePeer()
			if  != nil {
				return fmt.Errorf("unable to decode pollAnswerVoters#3645230a: field recent_voters: %w", )
			}
			.RecentVoters = append(.RecentVoters, )
		}
	}
	return nil
}

// SetChosen sets value of Chosen conditional field.
func ( *PollAnswerVoters) ( bool) {
	if  {
		.Flags.Set(0)
		.Chosen = true
	} else {
		.Flags.Unset(0)
		.Chosen = false
	}
}

// GetChosen returns value of Chosen conditional field.
func ( *PollAnswerVoters) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetCorrect sets value of Correct conditional field.
func ( *PollAnswerVoters) ( bool) {
	if  {
		.Flags.Set(1)
		.Correct = true
	} else {
		.Flags.Unset(1)
		.Correct = false
	}
}

// GetCorrect returns value of Correct conditional field.
func ( *PollAnswerVoters) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetOption returns value of Option field.
func ( *PollAnswerVoters) () ( []byte) {
	if  == nil {
		return
	}
	return .Option
}

// SetVoters sets value of Voters conditional field.
func ( *PollAnswerVoters) ( int) {
	.Flags.Set(2)
	.Voters = 
}

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

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

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

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