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

// PollAnswer represents TL type `pollAnswer#4b7d786a`.
// A possible answer of a poll
//
// See https://core.telegram.org/constructor/pollAnswer for reference.
type PollAnswer struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Textual representation of the answer (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
	Text TextWithEntities
	// The param that has to be passed to messages.sendVote¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.sendVote
	Option []byte
	// Media field of PollAnswer.
	//
	// Use SetMedia and GetMedia helpers.
	Media MessageMediaClass
	// AddedBy field of PollAnswer.
	//
	// Use SetAddedBy and GetAddedBy helpers.
	AddedBy PeerClass
	// Date field of PollAnswer.
	//
	// Use SetDate and GetDate helpers.
	Date int
}

// PollAnswerTypeID is TL type id of PollAnswer.
const PollAnswerTypeID = 0x4b7d786a

// construct implements constructor of PollAnswerClass.
func ( PollAnswer) () PollAnswerClass { return & }

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

	_ PollAnswerClass = &PollAnswer{}
)

func ( *PollAnswer) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Text.Zero()) {
		return false
	}
	if !(.Option == nil) {
		return false
	}
	if !(.Media == nil) {
		return false
	}
	if !(.AddedBy == nil) {
		return false
	}
	if !(.Date == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PollAnswer from given interface.
func ( *PollAnswer) ( interface {
	() ( TextWithEntities)
	() ( []byte)
	() ( MessageMediaClass,  bool)
	() ( PeerClass,  bool)
	() ( int,  bool)
}) {
	.Text = .()
	.Option = .()
	if ,  := .();  {
		.Media = 
	}

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *PollAnswer) () tdp.Type {
	 := tdp.Type{
		Name: "pollAnswer",
		ID:   PollAnswerTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Text",
			SchemaName: "text",
		},
		{
			Name:       "Option",
			SchemaName: "option",
		},
		{
			Name:       "Media",
			SchemaName: "media",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "AddedBy",
			SchemaName: "added_by",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Date",
			SchemaName: "date",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PollAnswer) () {
	if !(.Media == nil) {
		.Flags.Set(0)
	}
	if !(.AddedBy == nil) {
		.Flags.Set(1)
	}
	if !(.Date == 0) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *PollAnswer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pollAnswer#4b7d786a as nil")
	}
	.PutID(PollAnswerTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PollAnswer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pollAnswer#4b7d786a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode pollAnswer#4b7d786a: field flags: %w", )
	}
	if  := .Text.Encode();  != nil {
		return fmt.Errorf("unable to encode pollAnswer#4b7d786a: field text: %w", )
	}
	.PutBytes(.Option)
	if .Flags.Has(0) {
		if .Media == nil {
			return fmt.Errorf("unable to encode pollAnswer#4b7d786a: field media is nil")
		}
		if  := .Media.Encode();  != nil {
			return fmt.Errorf("unable to encode pollAnswer#4b7d786a: field media: %w", )
		}
	}
	if .Flags.Has(1) {
		if .AddedBy == nil {
			return fmt.Errorf("unable to encode pollAnswer#4b7d786a: field added_by is nil")
		}
		if  := .AddedBy.Encode();  != nil {
			return fmt.Errorf("unable to encode pollAnswer#4b7d786a: field added_by: %w", )
		}
	}
	if .Flags.Has(1) {
		.PutInt(.Date)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PollAnswer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pollAnswer#4b7d786a to nil")
	}
	if  := .ConsumeID(PollAnswerTypeID);  != nil {
		return fmt.Errorf("unable to decode pollAnswer#4b7d786a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PollAnswer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pollAnswer#4b7d786a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode pollAnswer#4b7d786a: field flags: %w", )
		}
	}
	{
		if  := .Text.Decode();  != nil {
			return fmt.Errorf("unable to decode pollAnswer#4b7d786a: field text: %w", )
		}
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode pollAnswer#4b7d786a: field option: %w", )
		}
		.Option = 
	}
	if .Flags.Has(0) {
		,  := DecodeMessageMedia()
		if  != nil {
			return fmt.Errorf("unable to decode pollAnswer#4b7d786a: field media: %w", )
		}
		.Media = 
	}
	if .Flags.Has(1) {
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode pollAnswer#4b7d786a: field added_by: %w", )
		}
		.AddedBy = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode pollAnswer#4b7d786a: field date: %w", )
		}
		.Date = 
	}
	return nil
}

// GetText returns value of Text field.
func ( *PollAnswer) () ( TextWithEntities) {
	if  == nil {
		return
	}
	return .Text
}

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

// SetMedia sets value of Media conditional field.
func ( *PollAnswer) ( MessageMediaClass) {
	.Flags.Set(0)
	.Media = 
}

// GetMedia returns value of Media conditional field and
// boolean which is true if field was set.
func ( *PollAnswer) () ( MessageMediaClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Media, true
}

// SetAddedBy sets value of AddedBy conditional field.
func ( *PollAnswer) ( PeerClass) {
	.Flags.Set(1)
	.AddedBy = 
}

// GetAddedBy returns value of AddedBy conditional field and
// boolean which is true if field was set.
func ( *PollAnswer) () ( PeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .AddedBy, true
}

// SetDate sets value of Date conditional field.
func ( *PollAnswer) ( int) {
	.Flags.Set(1)
	.Date = 
}

// GetDate returns value of Date conditional field and
// boolean which is true if field was set.
func ( *PollAnswer) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Date, true
}

// InputPollAnswer represents TL type `inputPollAnswer#199fed96`.
//
// See https://core.telegram.org/constructor/inputPollAnswer for reference.
type InputPollAnswer struct {
	// Flags field of InputPollAnswer.
	Flags bin.Fields
	// Text field of InputPollAnswer.
	Text TextWithEntities
	// Media field of InputPollAnswer.
	//
	// Use SetMedia and GetMedia helpers.
	Media InputMediaClass
}

// InputPollAnswerTypeID is TL type id of InputPollAnswer.
const InputPollAnswerTypeID = 0x199fed96

// construct implements constructor of PollAnswerClass.
func ( InputPollAnswer) () PollAnswerClass { return & }

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

	_ PollAnswerClass = &InputPollAnswer{}
)

func ( *InputPollAnswer) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Text.Zero()) {
		return false
	}
	if !(.Media == nil) {
		return false
	}

	return true
}

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

// FillFrom fills InputPollAnswer from given interface.
func ( *InputPollAnswer) ( interface {
	() ( TextWithEntities)
	() ( InputMediaClass,  bool)
}) {
	.Text = .()
	if ,  := .();  {
		.Media = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *InputPollAnswer) () tdp.Type {
	 := tdp.Type{
		Name: "inputPollAnswer",
		ID:   InputPollAnswerTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Text",
			SchemaName: "text",
		},
		{
			Name:       "Media",
			SchemaName: "media",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *InputPollAnswer) () {
	if !(.Media == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *InputPollAnswer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode inputPollAnswer#199fed96 as nil")
	}
	.PutID(InputPollAnswerTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *InputPollAnswer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode inputPollAnswer#199fed96 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode inputPollAnswer#199fed96: field flags: %w", )
	}
	if  := .Text.Encode();  != nil {
		return fmt.Errorf("unable to encode inputPollAnswer#199fed96: field text: %w", )
	}
	if .Flags.Has(0) {
		if .Media == nil {
			return fmt.Errorf("unable to encode inputPollAnswer#199fed96: field media is nil")
		}
		if  := .Media.Encode();  != nil {
			return fmt.Errorf("unable to encode inputPollAnswer#199fed96: field media: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *InputPollAnswer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode inputPollAnswer#199fed96 to nil")
	}
	if  := .ConsumeID(InputPollAnswerTypeID);  != nil {
		return fmt.Errorf("unable to decode inputPollAnswer#199fed96: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *InputPollAnswer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode inputPollAnswer#199fed96 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode inputPollAnswer#199fed96: field flags: %w", )
		}
	}
	{
		if  := .Text.Decode();  != nil {
			return fmt.Errorf("unable to decode inputPollAnswer#199fed96: field text: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := DecodeInputMedia()
		if  != nil {
			return fmt.Errorf("unable to decode inputPollAnswer#199fed96: field media: %w", )
		}
		.Media = 
	}
	return nil
}

// GetText returns value of Text field.
func ( *InputPollAnswer) () ( TextWithEntities) {
	if  == nil {
		return
	}
	return .Text
}

// SetMedia sets value of Media conditional field.
func ( *InputPollAnswer) ( InputMediaClass) {
	.Flags.Set(0)
	.Media = 
}

// GetMedia returns value of Media conditional field and
// boolean which is true if field was set.
func ( *InputPollAnswer) () ( InputMediaClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Media, true
}

// PollAnswerClassName is schema name of PollAnswerClass.
const PollAnswerClassName = "PollAnswer"

// PollAnswerClass represents PollAnswer generic type.
//
// See https://core.telegram.org/type/PollAnswer for reference.
//
// Constructors:
//   - [PollAnswer]
//   - [InputPollAnswer]
//
// Example:
//
//	g, err := tg.DecodePollAnswer(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.PollAnswer: // pollAnswer#4b7d786a
//	case *tg.InputPollAnswer: // inputPollAnswer#199fed96
//	default: panic(v)
//	}
type PollAnswerClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PollAnswerClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// Textual representation of the answer (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
	GetText() (value TextWithEntities)
}

// DecodePollAnswer implements binary de-serialization for PollAnswerClass.
func ( *bin.Buffer) (PollAnswerClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case PollAnswerTypeID:
		// Decoding pollAnswer#4b7d786a.
		 := PollAnswer{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PollAnswerClass: %w", )
		}
		return &, nil
	case InputPollAnswerTypeID:
		// Decoding inputPollAnswer#199fed96.
		 := InputPollAnswer{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PollAnswerClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode PollAnswerClass: %w", bin.NewUnexpectedID())
	}
}

// PollAnswer boxes the PollAnswerClass providing a helper.
type PollAnswerBox struct {
	PollAnswer PollAnswerClass
}

// Decode implements bin.Decoder for PollAnswerBox.
func ( *PollAnswerBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode PollAnswerBox to nil")
	}
	,  := DecodePollAnswer()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.PollAnswer = 
	return nil
}

// Encode implements bin.Encode for PollAnswerBox.
func ( *PollAnswerBox) ( *bin.Buffer) error {
	if  == nil || .PollAnswer == nil {
		return fmt.Errorf("unable to encode PollAnswerClass as nil")
	}
	return .PollAnswer.Encode()
}