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

// SecureRequiredType represents TL type `secureRequiredType#829d99da`.
// Required type
//
// See https://core.telegram.org/constructor/secureRequiredType for reference.
type SecureRequiredType struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Native names
	NativeNames bool
	// Is a selfie required
	SelfieRequired bool
	// Is a translation required
	TranslationRequired bool
	// Secure value type
	Type SecureValueTypeClass
}

// SecureRequiredTypeTypeID is TL type id of SecureRequiredType.
const SecureRequiredTypeTypeID = 0x829d99da

// construct implements constructor of SecureRequiredTypeClass.
func ( SecureRequiredType) () SecureRequiredTypeClass { return & }

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

	_ SecureRequiredTypeClass = &SecureRequiredType{}
)

func ( *SecureRequiredType) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.NativeNames == false) {
		return false
	}
	if !(.SelfieRequired == false) {
		return false
	}
	if !(.TranslationRequired == false) {
		return false
	}
	if !(.Type == nil) {
		return false
	}

	return true
}

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

// FillFrom fills SecureRequiredType from given interface.
func ( *SecureRequiredType) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( SecureValueTypeClass)
}) {
	.NativeNames = .()
	.SelfieRequired = .()
	.TranslationRequired = .()
	.Type = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *SecureRequiredType) () tdp.Type {
	 := tdp.Type{
		Name: "secureRequiredType",
		ID:   SecureRequiredTypeTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "NativeNames",
			SchemaName: "native_names",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "SelfieRequired",
			SchemaName: "selfie_required",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "TranslationRequired",
			SchemaName: "translation_required",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Type",
			SchemaName: "type",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *SecureRequiredType) () {
	if !(.NativeNames == false) {
		.Flags.Set(0)
	}
	if !(.SelfieRequired == false) {
		.Flags.Set(1)
	}
	if !(.TranslationRequired == false) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *SecureRequiredType) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode secureRequiredType#829d99da as nil")
	}
	.PutID(SecureRequiredTypeTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *SecureRequiredType) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode secureRequiredType#829d99da as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode secureRequiredType#829d99da: field flags: %w", )
	}
	if .Type == nil {
		return fmt.Errorf("unable to encode secureRequiredType#829d99da: field type is nil")
	}
	if  := .Type.Encode();  != nil {
		return fmt.Errorf("unable to encode secureRequiredType#829d99da: field type: %w", )
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *SecureRequiredType) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode secureRequiredType#829d99da to nil")
	}
	if  := .ConsumeID(SecureRequiredTypeTypeID);  != nil {
		return fmt.Errorf("unable to decode secureRequiredType#829d99da: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *SecureRequiredType) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode secureRequiredType#829d99da to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode secureRequiredType#829d99da: field flags: %w", )
		}
	}
	.NativeNames = .Flags.Has(0)
	.SelfieRequired = .Flags.Has(1)
	.TranslationRequired = .Flags.Has(2)
	{
		,  := DecodeSecureValueType()
		if  != nil {
			return fmt.Errorf("unable to decode secureRequiredType#829d99da: field type: %w", )
		}
		.Type = 
	}
	return nil
}

// SetNativeNames sets value of NativeNames conditional field.
func ( *SecureRequiredType) ( bool) {
	if  {
		.Flags.Set(0)
		.NativeNames = true
	} else {
		.Flags.Unset(0)
		.NativeNames = false
	}
}

// GetNativeNames returns value of NativeNames conditional field.
func ( *SecureRequiredType) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetSelfieRequired sets value of SelfieRequired conditional field.
func ( *SecureRequiredType) ( bool) {
	if  {
		.Flags.Set(1)
		.SelfieRequired = true
	} else {
		.Flags.Unset(1)
		.SelfieRequired = false
	}
}

// GetSelfieRequired returns value of SelfieRequired conditional field.
func ( *SecureRequiredType) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetTranslationRequired sets value of TranslationRequired conditional field.
func ( *SecureRequiredType) ( bool) {
	if  {
		.Flags.Set(2)
		.TranslationRequired = true
	} else {
		.Flags.Unset(2)
		.TranslationRequired = false
	}
}

// GetTranslationRequired returns value of TranslationRequired conditional field.
func ( *SecureRequiredType) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// GetType returns value of Type field.
func ( *SecureRequiredType) () ( SecureValueTypeClass) {
	if  == nil {
		return
	}
	return .Type
}

// SecureRequiredTypeOneOf represents TL type `secureRequiredTypeOneOf#27477b4`.
// One of
//
// See https://core.telegram.org/constructor/secureRequiredTypeOneOf for reference.
type SecureRequiredTypeOneOf struct {
	// Secure required value types
	Types []SecureRequiredTypeClass
}

// SecureRequiredTypeOneOfTypeID is TL type id of SecureRequiredTypeOneOf.
const SecureRequiredTypeOneOfTypeID = 0x27477b4

// construct implements constructor of SecureRequiredTypeClass.
func ( SecureRequiredTypeOneOf) () SecureRequiredTypeClass { return & }

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

	_ SecureRequiredTypeClass = &SecureRequiredTypeOneOf{}
)

func ( *SecureRequiredTypeOneOf) () bool {
	if  == nil {
		return true
	}
	if !(.Types == nil) {
		return false
	}

	return true
}

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

// FillFrom fills SecureRequiredTypeOneOf from given interface.
func ( *SecureRequiredTypeOneOf) ( interface {
	() ( []SecureRequiredTypeClass)
}) {
	.Types = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *SecureRequiredTypeOneOf) () tdp.Type {
	 := tdp.Type{
		Name: "secureRequiredTypeOneOf",
		ID:   SecureRequiredTypeOneOfTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Types",
			SchemaName: "types",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *SecureRequiredTypeOneOf) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode secureRequiredTypeOneOf#27477b4 as nil")
	}
	.PutID(SecureRequiredTypeOneOfTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *SecureRequiredTypeOneOf) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode secureRequiredTypeOneOf#27477b4 as nil")
	}
	.PutVectorHeader(len(.Types))
	for ,  := range .Types {
		if  == nil {
			return fmt.Errorf("unable to encode secureRequiredTypeOneOf#27477b4: field types element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode secureRequiredTypeOneOf#27477b4: field types element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *SecureRequiredTypeOneOf) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode secureRequiredTypeOneOf#27477b4 to nil")
	}
	if  := .ConsumeID(SecureRequiredTypeOneOfTypeID);  != nil {
		return fmt.Errorf("unable to decode secureRequiredTypeOneOf#27477b4: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *SecureRequiredTypeOneOf) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode secureRequiredTypeOneOf#27477b4 to nil")
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode secureRequiredTypeOneOf#27477b4: field types: %w", )
		}

		if  > 0 {
			.Types = make([]SecureRequiredTypeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeSecureRequiredType()
			if  != nil {
				return fmt.Errorf("unable to decode secureRequiredTypeOneOf#27477b4: field types: %w", )
			}
			.Types = append(.Types, )
		}
	}
	return nil
}

// GetTypes returns value of Types field.
func ( *SecureRequiredTypeOneOf) () ( []SecureRequiredTypeClass) {
	if  == nil {
		return
	}
	return .Types
}

// MapTypes returns field Types wrapped in SecureRequiredTypeClassArray helper.
func ( *SecureRequiredTypeOneOf) () ( SecureRequiredTypeClassArray) {
	return SecureRequiredTypeClassArray(.Types)
}

// SecureRequiredTypeClassName is schema name of SecureRequiredTypeClass.
const SecureRequiredTypeClassName = "SecureRequiredType"

// SecureRequiredTypeClass represents SecureRequiredType generic type.
//
// See https://core.telegram.org/type/SecureRequiredType for reference.
//
// Example:
//
//	g, err := tg.DecodeSecureRequiredType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.SecureRequiredType: // secureRequiredType#829d99da
//	case *tg.SecureRequiredTypeOneOf: // secureRequiredTypeOneOf#27477b4
//	default: panic(v)
//	}
type SecureRequiredTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() SecureRequiredTypeClass

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

// DecodeSecureRequiredType implements binary de-serialization for SecureRequiredTypeClass.
func ( *bin.Buffer) (SecureRequiredTypeClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case SecureRequiredTypeTypeID:
		// Decoding secureRequiredType#829d99da.
		 := SecureRequiredType{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode SecureRequiredTypeClass: %w", )
		}
		return &, nil
	case SecureRequiredTypeOneOfTypeID:
		// Decoding secureRequiredTypeOneOf#27477b4.
		 := SecureRequiredTypeOneOf{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode SecureRequiredTypeClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode SecureRequiredTypeClass: %w", bin.NewUnexpectedID())
	}
}

// SecureRequiredType boxes the SecureRequiredTypeClass providing a helper.
type SecureRequiredTypeBox struct {
	SecureRequiredType SecureRequiredTypeClass
}

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

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