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

// SecureValue represents TL type `secureValue#187fa0ca`.
// Secure value
//
// See https://core.telegram.org/constructor/secureValue for reference.
type SecureValue struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Secure passport¹ value type
	//
	// Links:
	//  1) https://core.telegram.org/passport
	Type SecureValueTypeClass
	// Encrypted Telegram Passport¹ element data
	//
	// Links:
	//  1) https://core.telegram.org/passport
	//
	// Use SetData and GetData helpers.
	Data SecureData
	// Encrypted passport¹ file with the front side of the document
	//
	// Links:
	//  1) https://core.telegram.org/passport
	//
	// Use SetFrontSide and GetFrontSide helpers.
	FrontSide SecureFileClass
	// Encrypted passport¹ file with the reverse side of the document
	//
	// Links:
	//  1) https://core.telegram.org/passport
	//
	// Use SetReverseSide and GetReverseSide helpers.
	ReverseSide SecureFileClass
	// Encrypted passport¹ file with a selfie of the user holding the document
	//
	// Links:
	//  1) https://core.telegram.org/passport
	//
	// Use SetSelfie and GetSelfie helpers.
	Selfie SecureFileClass
	// Array of encrypted passport¹ files with translated versions of the provided documents
	//
	// Links:
	//  1) https://core.telegram.org/passport
	//
	// Use SetTranslation and GetTranslation helpers.
	Translation []SecureFileClass
	// Array of encrypted passport¹ files with photos the of the documents
	//
	// Links:
	//  1) https://core.telegram.org/passport
	//
	// Use SetFiles and GetFiles helpers.
	Files []SecureFileClass
	// Plaintext verified passport¹ data
	//
	// Links:
	//  1) https://core.telegram.org/passport
	//
	// Use SetPlainData and GetPlainData helpers.
	PlainData SecurePlainDataClass
	// Data hash
	Hash []byte
}

// SecureValueTypeID is TL type id of SecureValue.
const SecureValueTypeID = 0x187fa0ca

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

func ( *SecureValue) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Type == nil) {
		return false
	}
	if !(.Data.Zero()) {
		return false
	}
	if !(.FrontSide == nil) {
		return false
	}
	if !(.ReverseSide == nil) {
		return false
	}
	if !(.Selfie == nil) {
		return false
	}
	if !(.Translation == nil) {
		return false
	}
	if !(.Files == nil) {
		return false
	}
	if !(.PlainData == nil) {
		return false
	}
	if !(.Hash == nil) {
		return false
	}

	return true
}

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

// FillFrom fills SecureValue from given interface.
func ( *SecureValue) ( interface {
	() ( SecureValueTypeClass)
	() ( SecureData,  bool)
	() ( SecureFileClass,  bool)
	() ( SecureFileClass,  bool)
	() ( SecureFileClass,  bool)
	() ( []SecureFileClass,  bool)
	() ( []SecureFileClass,  bool)
	() ( SecurePlainDataClass,  bool)
	() ( []byte)
}) {
	.Type = .()
	if ,  := .();  {
		.Data = 
	}

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

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

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

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

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

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

	.Hash = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *SecureValue) () tdp.Type {
	 := tdp.Type{
		Name: "secureValue",
		ID:   SecureValueTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Type",
			SchemaName: "type",
		},
		{
			Name:       "Data",
			SchemaName: "data",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "FrontSide",
			SchemaName: "front_side",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ReverseSide",
			SchemaName: "reverse_side",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Selfie",
			SchemaName: "selfie",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Translation",
			SchemaName: "translation",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "Files",
			SchemaName: "files",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "PlainData",
			SchemaName: "plain_data",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *SecureValue) () {
	if !(.Data.Zero()) {
		.Flags.Set(0)
	}
	if !(.FrontSide == nil) {
		.Flags.Set(1)
	}
	if !(.ReverseSide == nil) {
		.Flags.Set(2)
	}
	if !(.Selfie == nil) {
		.Flags.Set(3)
	}
	if !(.Translation == nil) {
		.Flags.Set(6)
	}
	if !(.Files == nil) {
		.Flags.Set(4)
	}
	if !(.PlainData == nil) {
		.Flags.Set(5)
	}
}

// Encode implements bin.Encoder.
func ( *SecureValue) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode secureValue#187fa0ca as nil")
	}
	.PutID(SecureValueTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *SecureValue) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode secureValue#187fa0ca as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode secureValue#187fa0ca: field flags: %w", )
	}
	if .Type == nil {
		return fmt.Errorf("unable to encode secureValue#187fa0ca: field type is nil")
	}
	if  := .Type.Encode();  != nil {
		return fmt.Errorf("unable to encode secureValue#187fa0ca: field type: %w", )
	}
	if .Flags.Has(0) {
		if  := .Data.Encode();  != nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field data: %w", )
		}
	}
	if .Flags.Has(1) {
		if .FrontSide == nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field front_side is nil")
		}
		if  := .FrontSide.Encode();  != nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field front_side: %w", )
		}
	}
	if .Flags.Has(2) {
		if .ReverseSide == nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field reverse_side is nil")
		}
		if  := .ReverseSide.Encode();  != nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field reverse_side: %w", )
		}
	}
	if .Flags.Has(3) {
		if .Selfie == nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field selfie is nil")
		}
		if  := .Selfie.Encode();  != nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field selfie: %w", )
		}
	}
	if .Flags.Has(6) {
		.PutVectorHeader(len(.Translation))
		for ,  := range .Translation {
			if  == nil {
				return fmt.Errorf("unable to encode secureValue#187fa0ca: field translation element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode secureValue#187fa0ca: field translation element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(4) {
		.PutVectorHeader(len(.Files))
		for ,  := range .Files {
			if  == nil {
				return fmt.Errorf("unable to encode secureValue#187fa0ca: field files element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode secureValue#187fa0ca: field files element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(5) {
		if .PlainData == nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field plain_data is nil")
		}
		if  := .PlainData.Encode();  != nil {
			return fmt.Errorf("unable to encode secureValue#187fa0ca: field plain_data: %w", )
		}
	}
	.PutBytes(.Hash)
	return nil
}

// Decode implements bin.Decoder.
func ( *SecureValue) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode secureValue#187fa0ca to nil")
	}
	if  := .ConsumeID(SecureValueTypeID);  != nil {
		return fmt.Errorf("unable to decode secureValue#187fa0ca: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *SecureValue) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode secureValue#187fa0ca to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field flags: %w", )
		}
	}
	{
		,  := DecodeSecureValueType()
		if  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field type: %w", )
		}
		.Type = 
	}
	if .Flags.Has(0) {
		if  := .Data.Decode();  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field data: %w", )
		}
	}
	if .Flags.Has(1) {
		,  := DecodeSecureFile()
		if  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field front_side: %w", )
		}
		.FrontSide = 
	}
	if .Flags.Has(2) {
		,  := DecodeSecureFile()
		if  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field reverse_side: %w", )
		}
		.ReverseSide = 
	}
	if .Flags.Has(3) {
		,  := DecodeSecureFile()
		if  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field selfie: %w", )
		}
		.Selfie = 
	}
	if .Flags.Has(6) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field translation: %w", )
		}

		if  > 0 {
			.Translation = make([]SecureFileClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeSecureFile()
			if  != nil {
				return fmt.Errorf("unable to decode secureValue#187fa0ca: field translation: %w", )
			}
			.Translation = append(.Translation, )
		}
	}
	if .Flags.Has(4) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field files: %w", )
		}

		if  > 0 {
			.Files = make([]SecureFileClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeSecureFile()
			if  != nil {
				return fmt.Errorf("unable to decode secureValue#187fa0ca: field files: %w", )
			}
			.Files = append(.Files, )
		}
	}
	if .Flags.Has(5) {
		,  := DecodeSecurePlainData()
		if  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field plain_data: %w", )
		}
		.PlainData = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode secureValue#187fa0ca: field hash: %w", )
		}
		.Hash = 
	}
	return nil
}

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

// SetData sets value of Data conditional field.
func ( *SecureValue) ( SecureData) {
	.Flags.Set(0)
	.Data = 
}

// GetData returns value of Data conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () ( SecureData,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Data, true
}

// SetFrontSide sets value of FrontSide conditional field.
func ( *SecureValue) ( SecureFileClass) {
	.Flags.Set(1)
	.FrontSide = 
}

// GetFrontSide returns value of FrontSide conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () ( SecureFileClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .FrontSide, true
}

// SetReverseSide sets value of ReverseSide conditional field.
func ( *SecureValue) ( SecureFileClass) {
	.Flags.Set(2)
	.ReverseSide = 
}

// GetReverseSide returns value of ReverseSide conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () ( SecureFileClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .ReverseSide, true
}

// SetSelfie sets value of Selfie conditional field.
func ( *SecureValue) ( SecureFileClass) {
	.Flags.Set(3)
	.Selfie = 
}

// GetSelfie returns value of Selfie conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () ( SecureFileClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Selfie, true
}

// SetTranslation sets value of Translation conditional field.
func ( *SecureValue) ( []SecureFileClass) {
	.Flags.Set(6)
	.Translation = 
}

// GetTranslation returns value of Translation conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () ( []SecureFileClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(6) {
		return , false
	}
	return .Translation, true
}

// SetFiles sets value of Files conditional field.
func ( *SecureValue) ( []SecureFileClass) {
	.Flags.Set(4)
	.Files = 
}

// GetFiles returns value of Files conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () ( []SecureFileClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .Files, true
}

// SetPlainData sets value of PlainData conditional field.
func ( *SecureValue) ( SecurePlainDataClass) {
	.Flags.Set(5)
	.PlainData = 
}

// GetPlainData returns value of PlainData conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () ( SecurePlainDataClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .PlainData, true
}

// GetHash returns value of Hash field.
func ( *SecureValue) () ( []byte) {
	if  == nil {
		return
	}
	return .Hash
}

// GetFrontSideAsNotEmpty returns mapped value of FrontSide conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () (*SecureFile, bool) {
	if ,  := .GetFrontSide();  {
		return .AsNotEmpty()
	}
	return nil, false
}

// GetReverseSideAsNotEmpty returns mapped value of ReverseSide conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () (*SecureFile, bool) {
	if ,  := .GetReverseSide();  {
		return .AsNotEmpty()
	}
	return nil, false
}

// GetSelfieAsNotEmpty returns mapped value of Selfie conditional field and
// boolean which is true if field was set.
func ( *SecureValue) () (*SecureFile, bool) {
	if ,  := .GetSelfie();  {
		return .AsNotEmpty()
	}
	return nil, false
}

// MapTranslation returns field Translation wrapped in SecureFileClassArray helper.
func ( *SecureValue) () ( SecureFileClassArray,  bool) {
	if !.Flags.Has(6) {
		return , false
	}
	return SecureFileClassArray(.Translation), true
}

// MapFiles returns field Files wrapped in SecureFileClassArray helper.
func ( *SecureValue) () ( SecureFileClassArray,  bool) {
	if !.Flags.Has(4) {
		return , false
	}
	return SecureFileClassArray(.Files), true
}