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

// AccountAuthorizationForm represents TL type `account.authorizationForm#ad2e1cd8`.
// Telegram Passport¹ authorization form
//
// Links:
//  1. https://core.telegram.org/passport
//
// See https://core.telegram.org/constructor/account.authorizationForm for reference.
type AccountAuthorizationForm struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Required Telegram Passport¹ documents
	//
	// Links:
	//  1) https://core.telegram.org/passport
	RequiredTypes []SecureRequiredTypeClass
	// Already submitted Telegram Passport¹ documents
	//
	// Links:
	//  1) https://core.telegram.org/passport
	Values []SecureValue
	// Telegram Passport¹ errors
	//
	// Links:
	//  1) https://core.telegram.org/passport
	Errors []SecureValueErrorClass
	// Info about the bot to which the form will be submitted
	Users []UserClass
	// URL of the service's privacy policy
	//
	// Use SetPrivacyPolicyURL and GetPrivacyPolicyURL helpers.
	PrivacyPolicyURL string
}

// AccountAuthorizationFormTypeID is TL type id of AccountAuthorizationForm.
const AccountAuthorizationFormTypeID = 0xad2e1cd8

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

func ( *AccountAuthorizationForm) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.RequiredTypes == nil) {
		return false
	}
	if !(.Values == nil) {
		return false
	}
	if !(.Errors == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}
	if !(.PrivacyPolicyURL == "") {
		return false
	}

	return true
}

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

// FillFrom fills AccountAuthorizationForm from given interface.
func ( *AccountAuthorizationForm) ( interface {
	() ( []SecureRequiredTypeClass)
	() ( []SecureValue)
	() ( []SecureValueErrorClass)
	() ( []UserClass)
	() ( string,  bool)
}) {
	.RequiredTypes = .()
	.Values = .()
	.Errors = .()
	.Users = .()
	if ,  := .();  {
		.PrivacyPolicyURL = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*AccountAuthorizationForm) () string {
	return "account.authorizationForm"
}

// TypeInfo returns info about TL type.
func ( *AccountAuthorizationForm) () tdp.Type {
	 := tdp.Type{
		Name: "account.authorizationForm",
		ID:   AccountAuthorizationFormTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "RequiredTypes",
			SchemaName: "required_types",
		},
		{
			Name:       "Values",
			SchemaName: "values",
		},
		{
			Name:       "Errors",
			SchemaName: "errors",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "PrivacyPolicyURL",
			SchemaName: "privacy_policy_url",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AccountAuthorizationForm) () {
	if !(.PrivacyPolicyURL == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *AccountAuthorizationForm) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.authorizationForm#ad2e1cd8 as nil")
	}
	.PutID(AccountAuthorizationFormTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccountAuthorizationForm) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.authorizationForm#ad2e1cd8 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode account.authorizationForm#ad2e1cd8: field flags: %w", )
	}
	.PutVectorHeader(len(.RequiredTypes))
	for ,  := range .RequiredTypes {
		if  == nil {
			return fmt.Errorf("unable to encode account.authorizationForm#ad2e1cd8: field required_types element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode account.authorizationForm#ad2e1cd8: field required_types element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Values))
	for ,  := range .Values {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode account.authorizationForm#ad2e1cd8: field values element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Errors))
	for ,  := range .Errors {
		if  == nil {
			return fmt.Errorf("unable to encode account.authorizationForm#ad2e1cd8: field errors element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode account.authorizationForm#ad2e1cd8: field errors element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode account.authorizationForm#ad2e1cd8: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode account.authorizationForm#ad2e1cd8: field users element with index %d: %w", , )
		}
	}
	if .Flags.Has(0) {
		.PutString(.PrivacyPolicyURL)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *AccountAuthorizationForm) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.authorizationForm#ad2e1cd8 to nil")
	}
	if  := .ConsumeID(AccountAuthorizationFormTypeID);  != nil {
		return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *AccountAuthorizationForm) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.authorizationForm#ad2e1cd8 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field flags: %w", )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field required_types: %w", )
		}

		if  > 0 {
			.RequiredTypes = make([]SecureRequiredTypeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeSecureRequiredType()
			if  != nil {
				return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field required_types: %w", )
			}
			.RequiredTypes = append(.RequiredTypes, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field values: %w", )
		}

		if  > 0 {
			.Values = make([]SecureValue, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  SecureValue
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field values: %w", )
			}
			.Values = append(.Values, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field errors: %w", )
		}

		if  > 0 {
			.Errors = make([]SecureValueErrorClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeSecureValueError()
			if  != nil {
				return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field errors: %w", )
			}
			.Errors = append(.Errors, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode account.authorizationForm#ad2e1cd8: field privacy_policy_url: %w", )
		}
		.PrivacyPolicyURL = 
	}
	return nil
}

// GetRequiredTypes returns value of RequiredTypes field.
func ( *AccountAuthorizationForm) () ( []SecureRequiredTypeClass) {
	if  == nil {
		return
	}
	return .RequiredTypes
}

// GetValues returns value of Values field.
func ( *AccountAuthorizationForm) () ( []SecureValue) {
	if  == nil {
		return
	}
	return .Values
}

// GetErrors returns value of Errors field.
func ( *AccountAuthorizationForm) () ( []SecureValueErrorClass) {
	if  == nil {
		return
	}
	return .Errors
}

// GetUsers returns value of Users field.
func ( *AccountAuthorizationForm) () ( []UserClass) {
	if  == nil {
		return
	}
	return .Users
}

// SetPrivacyPolicyURL sets value of PrivacyPolicyURL conditional field.
func ( *AccountAuthorizationForm) ( string) {
	.Flags.Set(0)
	.PrivacyPolicyURL = 
}

// GetPrivacyPolicyURL returns value of PrivacyPolicyURL conditional field and
// boolean which is true if field was set.
func ( *AccountAuthorizationForm) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .PrivacyPolicyURL, true
}

// MapRequiredTypes returns field RequiredTypes wrapped in SecureRequiredTypeClassArray helper.
func ( *AccountAuthorizationForm) () ( SecureRequiredTypeClassArray) {
	return SecureRequiredTypeClassArray(.RequiredTypes)
}

// MapErrors returns field Errors wrapped in SecureValueErrorClassArray helper.
func ( *AccountAuthorizationForm) () ( SecureValueErrorClassArray) {
	return SecureValueErrorClassArray(.Errors)
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func ( *AccountAuthorizationForm) () ( UserClassArray) {
	return UserClassArray(.Users)
}