// Code generated by smithy-go-codegen DO NOT EDIT.

package awscryptographyencryptionsdksmithygenerated

import (
	"github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsCryptographyMaterialProvidersTypes"
	"github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/awscryptographymaterialproviderssmithygenerated"
	"github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/awscryptographymaterialproviderssmithygeneratedtypes"
	"github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/awscryptographyprimitivessmithygenerated"
	"github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/UTF8"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/AwsCryptographyEncryptionSdkTypes"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/awscryptographyencryptionsdksmithygeneratedtypes"
	"github.com/dafny-lang/DafnyRuntimeGo/v4/dafny"
)

func DecryptInput_FromDafny(dafnyInput AwsCryptographyEncryptionSdkTypes.DecryptInput) awscryptographyencryptionsdksmithygeneratedtypes.DecryptInput {

	return awscryptographyencryptionsdksmithygeneratedtypes.DecryptInput{Ciphertext: Aws_cryptography_encryptionSdk_DecryptInput_ciphertext_FromDafny(dafnyInput.Dtor_ciphertext()),
		MaterialsManager: func() awscryptographymaterialproviderssmithygeneratedtypes.ICryptographicMaterialsManager {
			if dafnyInput.Dtor_materialsManager().UnwrapOr(nil) == nil {
				return nil
			}
			return awscryptographymaterialproviderssmithygenerated.CryptographicMaterialsManager_FromDafny(dafnyInput.Dtor_materialsManager().UnwrapOr(nil).(AwsCryptographyMaterialProvidersTypes.ICryptographicMaterialsManager))
		}(),
		Keyring: func() awscryptographymaterialproviderssmithygeneratedtypes.IKeyring {
			if dafnyInput.Dtor_keyring().UnwrapOr(nil) == nil {
				return nil
			}
			return awscryptographymaterialproviderssmithygenerated.Keyring_FromDafny(dafnyInput.Dtor_keyring().UnwrapOr(nil).(AwsCryptographyMaterialProvidersTypes.IKeyring))
		}(),
		EncryptionContext: Aws_cryptography_encryptionSdk_DecryptInput_encryptionContext_FromDafny(dafnyInput.Dtor_encryptionContext().UnwrapOr(nil)),
	}

}

func DecryptOutput_FromDafny(dafnyOutput AwsCryptographyEncryptionSdkTypes.DecryptOutput) awscryptographyencryptionsdksmithygeneratedtypes.DecryptOutput {

	return awscryptographyencryptionsdksmithygeneratedtypes.DecryptOutput{Plaintext: Aws_cryptography_encryptionSdk_DecryptOutput_plaintext_FromDafny(dafnyOutput.Dtor_plaintext()),
		EncryptionContext: Aws_cryptography_encryptionSdk_DecryptOutput_encryptionContext_FromDafny(dafnyOutput.Dtor_encryptionContext()),
		AlgorithmSuiteId:  Aws_cryptography_encryptionSdk_DecryptOutput_algorithmSuiteId_FromDafny(dafnyOutput.Dtor_algorithmSuiteId()),
	}

}

func EncryptInput_FromDafny(dafnyInput AwsCryptographyEncryptionSdkTypes.EncryptInput) awscryptographyencryptionsdksmithygeneratedtypes.EncryptInput {

	return awscryptographyencryptionsdksmithygeneratedtypes.EncryptInput{Plaintext: Aws_cryptography_encryptionSdk_EncryptInput_plaintext_FromDafny(dafnyInput.Dtor_plaintext()),
		EncryptionContext: Aws_cryptography_encryptionSdk_EncryptInput_encryptionContext_FromDafny(dafnyInput.Dtor_encryptionContext().UnwrapOr(nil)),
		MaterialsManager: func() awscryptographymaterialproviderssmithygeneratedtypes.ICryptographicMaterialsManager {
			if dafnyInput.Dtor_materialsManager().UnwrapOr(nil) == nil {
				return nil
			}
			return awscryptographymaterialproviderssmithygenerated.CryptographicMaterialsManager_FromDafny(dafnyInput.Dtor_materialsManager().UnwrapOr(nil).(AwsCryptographyMaterialProvidersTypes.ICryptographicMaterialsManager))
		}(),
		Keyring: func() awscryptographymaterialproviderssmithygeneratedtypes.IKeyring {
			if dafnyInput.Dtor_keyring().UnwrapOr(nil) == nil {
				return nil
			}
			return awscryptographymaterialproviderssmithygenerated.Keyring_FromDafny(dafnyInput.Dtor_keyring().UnwrapOr(nil).(AwsCryptographyMaterialProvidersTypes.IKeyring))
		}(),
		AlgorithmSuiteId: Aws_cryptography_encryptionSdk_EncryptInput_algorithmSuiteId_FromDafny(dafnyInput.Dtor_algorithmSuiteId().UnwrapOr(nil)),
		FrameLength:      Aws_cryptography_encryptionSdk_EncryptInput_frameLength_FromDafny(dafnyInput.Dtor_frameLength().UnwrapOr(nil)),
	}

}

func EncryptOutput_FromDafny(dafnyOutput AwsCryptographyEncryptionSdkTypes.EncryptOutput) awscryptographyencryptionsdksmithygeneratedtypes.EncryptOutput {

	return awscryptographyencryptionsdksmithygeneratedtypes.EncryptOutput{Ciphertext: Aws_cryptography_encryptionSdk_EncryptOutput_ciphertext_FromDafny(dafnyOutput.Dtor_ciphertext()),
		EncryptionContext: Aws_cryptography_encryptionSdk_EncryptOutput_encryptionContext_FromDafny(dafnyOutput.Dtor_encryptionContext()),
		AlgorithmSuiteId:  Aws_cryptography_encryptionSdk_EncryptOutput_algorithmSuiteId_FromDafny(dafnyOutput.Dtor_algorithmSuiteId()),
	}

}

func AwsEncryptionSdkException_FromDafny(dafnyOutput AwsCryptographyEncryptionSdkTypes.Error) awscryptographyencryptionsdksmithygeneratedtypes.AwsEncryptionSdkException {
	return awscryptographyencryptionsdksmithygeneratedtypes.AwsEncryptionSdkException{Message: Aws_cryptography_encryptionSdk_AwsEncryptionSdkException_message_FromDafny(dafnyOutput.Dtor_message())}

}

func CollectionOfErrors_Output_FromDafny(dafnyOutput AwsCryptographyEncryptionSdkTypes.Error) awscryptographyencryptionsdksmithygeneratedtypes.CollectionOfErrors {
	listOfErrors := dafnyOutput.Dtor_list()
	message := dafnyOutput.Dtor_message()
	t := awscryptographyencryptionsdksmithygeneratedtypes.CollectionOfErrors{}
	for i := dafny.Iterate(listOfErrors); ; {
		val, ok := i()
		if !ok {
			break
		}
		err := val.(AwsCryptographyEncryptionSdkTypes.Error)
		t.ListOfErrors = append(t.ListOfErrors, Error_FromDafny(err))

	}
	t.Message = func() string {
		a := UTF8.Encode(message.(dafny.Sequence)).Dtor_value()
		s := string(dafny.ToByteArray(a.(dafny.Sequence)))
		return s
	}()
	return t
}
func OpaqueError_Output_FromDafny(dafnyOutput AwsCryptographyEncryptionSdkTypes.Error) awscryptographyencryptionsdksmithygeneratedtypes.OpaqueError {
	return awscryptographyencryptionsdksmithygeneratedtypes.OpaqueError{
		ErrObject: dafnyOutput.Dtor_obj(),
	}
}

func Error_FromDafny(err AwsCryptographyEncryptionSdkTypes.Error) error {
	// Service Errors
	if err.Is_AwsEncryptionSdkException() {
		return AwsEncryptionSdkException_FromDafny(err)
	}

	//DependentErrors
	if err.Is_AwsCryptographyPrimitives() {
		return awscryptographyprimitivessmithygenerated.Error_FromDafny(err.Dtor_AwsCryptographyPrimitives())
	}

	if err.Is_AwsCryptographyMaterialProviders() {
		return awscryptographymaterialproviderssmithygenerated.Error_FromDafny(err.Dtor_AwsCryptographyMaterialProviders())
	}

	//Unmodelled Errors
	if err.Is_CollectionOfErrors() {
		return CollectionOfErrors_Output_FromDafny(err)
	}

	return OpaqueError_Output_FromDafny(err)
}

func AwsEncryptionSdkConfig_FromDafny(dafnyOutput AwsCryptographyEncryptionSdkTypes.AwsEncryptionSdkConfig) awscryptographyencryptionsdksmithygeneratedtypes.AwsEncryptionSdkConfig {
	return awscryptographyencryptionsdksmithygeneratedtypes.AwsEncryptionSdkConfig{CommitmentPolicy: Aws_cryptography_encryptionSdk_AwsEncryptionSdkConfig_commitmentPolicy_FromDafny(dafnyOutput.Dtor_commitmentPolicy().UnwrapOr(nil)),
		MaxEncryptedDataKeys:  Aws_cryptography_encryptionSdk_AwsEncryptionSdkConfig_maxEncryptedDataKeys_FromDafny(dafnyOutput.Dtor_maxEncryptedDataKeys().UnwrapOr(nil)),
		NetV4_0_0_RetryPolicy: Aws_cryptography_encryptionSdk_AwsEncryptionSdkConfig_netV4_0_0_RetryPolicy_FromDafny(dafnyOutput.Dtor_netV4__0__0__RetryPolicy().UnwrapOr(nil)),
	}

}

func NetV4_0_0_RetryPolicy_FromDafny(input interface{}) awscryptographyencryptionsdksmithygeneratedtypes.NetV4_0_0_RetryPolicy {
	return func() awscryptographyencryptionsdksmithygeneratedtypes.NetV4_0_0_RetryPolicy {
		var u awscryptographyencryptionsdksmithygeneratedtypes.NetV4_0_0_RetryPolicy
		inputEnum := input.(AwsCryptographyEncryptionSdkTypes.NetV4__0__0__RetryPolicy)
		index := -1
		for allEnums := dafny.Iterate(AwsCryptographyEncryptionSdkTypes.CompanionStruct_NetV4__0__0__RetryPolicy_{}.AllSingletonConstructors()); ; {
			enum, ok := allEnums()
			if ok {
				index++
				if enum.(AwsCryptographyEncryptionSdkTypes.NetV4__0__0__RetryPolicy).Equals(inputEnum) {
					break
				}
			}
		}

		return u.Values()[index]
	}()

}

func Aws_cryptography_encryptionSdk_DecryptInput_ciphertext_FromDafny(input interface{}) []byte {
	return func() []byte {
		b := []byte{}
		if input == nil {
			return nil
		}
		for i := dafny.Iterate(input); ; {
			val, ok := i()
			if !ok {
				return b
			} else {
				b = append(b, val.(byte))
			}
		}
	}()
}
func Aws_cryptography_encryptionSdk_DecryptInput_encryptionContext_FromDafny(input interface{}) map[string]string {
	var m map[string]string = make(map[string]string)
	if input == nil {
		return nil
	}
	for i := dafny.Iterate(input.(dafny.Map).Items()); ; {
		val, ok := i()
		if !ok {
			break
		}
		m[awscryptographymaterialproviderssmithygenerated.Aws_cryptography_materialProviders_EncryptionContext_key_FromDafny((*val.(dafny.Tuple).IndexInt(0)))] = awscryptographymaterialproviderssmithygenerated.Aws_cryptography_materialProviders_EncryptionContext_value_FromDafny((*val.(dafny.Tuple).IndexInt(1)))
	}
	return m

}
func Aws_cryptography_encryptionSdk_DecryptOutput_plaintext_FromDafny(input interface{}) []byte {
	return func() []byte {
		b := []byte{}
		if input == nil {
			return nil
		}
		for i := dafny.Iterate(input); ; {
			val, ok := i()
			if !ok {
				return b
			} else {
				b = append(b, val.(byte))
			}
		}
	}()
}
func Aws_cryptography_encryptionSdk_DecryptOutput_encryptionContext_FromDafny(input interface{}) map[string]string {
	var m map[string]string = make(map[string]string)
	if input == nil {
		return nil
	}
	for i := dafny.Iterate(input.(dafny.Map).Items()); ; {
		val, ok := i()
		if !ok {
			break
		}
		m[awscryptographymaterialproviderssmithygenerated.Aws_cryptography_materialProviders_EncryptionContext_key_FromDafny((*val.(dafny.Tuple).IndexInt(0)))] = awscryptographymaterialproviderssmithygenerated.Aws_cryptography_materialProviders_EncryptionContext_value_FromDafny((*val.(dafny.Tuple).IndexInt(1)))
	}
	return m

}
func Aws_cryptography_encryptionSdk_DecryptOutput_algorithmSuiteId_FromDafny(input interface{}) awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId {
	return func() awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId {
		var u awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId
		inputEnum := input.(AwsCryptographyMaterialProvidersTypes.ESDKAlgorithmSuiteId)
		index := -1
		for allEnums := dafny.Iterate(AwsCryptographyMaterialProvidersTypes.CompanionStruct_ESDKAlgorithmSuiteId_{}.AllSingletonConstructors()); ; {
			enum, ok := allEnums()
			if ok {
				index++
				if enum.(AwsCryptographyMaterialProvidersTypes.ESDKAlgorithmSuiteId).Equals(inputEnum) {
					break
				}
			}
		}

		return u.Values()[index]
	}()
}
func Aws_cryptography_encryptionSdk_EncryptInput_plaintext_FromDafny(input interface{}) []byte {
	return func() []byte {
		b := []byte{}
		if input == nil {
			return nil
		}
		for i := dafny.Iterate(input); ; {
			val, ok := i()
			if !ok {
				return b
			} else {
				b = append(b, val.(byte))
			}
		}
	}()
}
func Aws_cryptography_encryptionSdk_EncryptInput_encryptionContext_FromDafny(input interface{}) map[string]string {
	var m map[string]string = make(map[string]string)
	if input == nil {
		return nil
	}
	for i := dafny.Iterate(input.(dafny.Map).Items()); ; {
		val, ok := i()
		if !ok {
			break
		}
		m[awscryptographymaterialproviderssmithygenerated.Aws_cryptography_materialProviders_EncryptionContext_key_FromDafny((*val.(dafny.Tuple).IndexInt(0)))] = awscryptographymaterialproviderssmithygenerated.Aws_cryptography_materialProviders_EncryptionContext_value_FromDafny((*val.(dafny.Tuple).IndexInt(1)))
	}
	return m

}
func Aws_cryptography_encryptionSdk_EncryptInput_algorithmSuiteId_FromDafny(input interface{}) *awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId {
	return func() *awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId {
		var u awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId
		if input == nil {
			return nil
		}
		inputEnum := input.(AwsCryptographyMaterialProvidersTypes.ESDKAlgorithmSuiteId)
		index := -1
		for allEnums := dafny.Iterate(AwsCryptographyMaterialProvidersTypes.CompanionStruct_ESDKAlgorithmSuiteId_{}.AllSingletonConstructors()); ; {
			enum, ok := allEnums()
			if ok {
				index++
				if enum.(AwsCryptographyMaterialProvidersTypes.ESDKAlgorithmSuiteId).Equals(inputEnum) {
					break
				}
			}
		}

		return &u.Values()[index]
	}()
}
func Aws_cryptography_encryptionSdk_EncryptInput_frameLength_FromDafny(input interface{}) *int64 {
	return func() *int64 {
		var b int64
		if input == nil {
			return nil
		}
		b = input.(int64)
		return &b
	}()
}
func Aws_cryptography_encryptionSdk_EncryptOutput_ciphertext_FromDafny(input interface{}) []byte {
	return func() []byte {
		b := []byte{}
		if input == nil {
			return nil
		}
		for i := dafny.Iterate(input); ; {
			val, ok := i()
			if !ok {
				return b
			} else {
				b = append(b, val.(byte))
			}
		}
	}()
}
func Aws_cryptography_encryptionSdk_EncryptOutput_encryptionContext_FromDafny(input interface{}) map[string]string {
	var m map[string]string = make(map[string]string)
	if input == nil {
		return nil
	}
	for i := dafny.Iterate(input.(dafny.Map).Items()); ; {
		val, ok := i()
		if !ok {
			break
		}
		m[awscryptographymaterialproviderssmithygenerated.Aws_cryptography_materialProviders_EncryptionContext_key_FromDafny((*val.(dafny.Tuple).IndexInt(0)))] = awscryptographymaterialproviderssmithygenerated.Aws_cryptography_materialProviders_EncryptionContext_value_FromDafny((*val.(dafny.Tuple).IndexInt(1)))
	}
	return m

}
func Aws_cryptography_encryptionSdk_EncryptOutput_algorithmSuiteId_FromDafny(input interface{}) awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId {
	return func() awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId {
		var u awscryptographymaterialproviderssmithygeneratedtypes.ESDKAlgorithmSuiteId
		inputEnum := input.(AwsCryptographyMaterialProvidersTypes.ESDKAlgorithmSuiteId)
		index := -1
		for allEnums := dafny.Iterate(AwsCryptographyMaterialProvidersTypes.CompanionStruct_ESDKAlgorithmSuiteId_{}.AllSingletonConstructors()); ; {
			enum, ok := allEnums()
			if ok {
				index++
				if enum.(AwsCryptographyMaterialProvidersTypes.ESDKAlgorithmSuiteId).Equals(inputEnum) {
					break
				}
			}
		}

		return u.Values()[index]
	}()
}
func Aws_cryptography_encryptionSdk_AwsEncryptionSdkException_message_FromDafny(input interface{}) string {
	return func() string {

		a := UTF8.Encode(input.(dafny.Sequence)).Dtor_value()
		s := string(dafny.ToByteArray(a.(dafny.Sequence)))

		return s
	}()
}
func Aws_cryptography_encryptionSdk_AwsEncryptionSdkConfig_commitmentPolicy_FromDafny(input interface{}) *awscryptographymaterialproviderssmithygeneratedtypes.ESDKCommitmentPolicy {
	return func() *awscryptographymaterialproviderssmithygeneratedtypes.ESDKCommitmentPolicy {
		var u awscryptographymaterialproviderssmithygeneratedtypes.ESDKCommitmentPolicy
		if input == nil {
			return nil
		}
		inputEnum := input.(AwsCryptographyMaterialProvidersTypes.ESDKCommitmentPolicy)
		index := -1
		for allEnums := dafny.Iterate(AwsCryptographyMaterialProvidersTypes.CompanionStruct_ESDKCommitmentPolicy_{}.AllSingletonConstructors()); ; {
			enum, ok := allEnums()
			if ok {
				index++
				if enum.(AwsCryptographyMaterialProvidersTypes.ESDKCommitmentPolicy).Equals(inputEnum) {
					break
				}
			}
		}

		return &u.Values()[index]
	}()
}
func Aws_cryptography_encryptionSdk_AwsEncryptionSdkConfig_maxEncryptedDataKeys_FromDafny(input interface{}) *int64 {
	return func() *int64 {
		var b int64
		if input == nil {
			return nil
		}
		b = input.(int64)
		return &b
	}()
}
func Aws_cryptography_encryptionSdk_AwsEncryptionSdkConfig_netV4_0_0_RetryPolicy_FromDafny(input interface{}) *awscryptographyencryptionsdksmithygeneratedtypes.NetV4_0_0_RetryPolicy {
	return func() *awscryptographyencryptionsdksmithygeneratedtypes.NetV4_0_0_RetryPolicy {
		var u awscryptographyencryptionsdksmithygeneratedtypes.NetV4_0_0_RetryPolicy
		if input == nil {
			return nil
		}
		inputEnum := input.(AwsCryptographyEncryptionSdkTypes.NetV4__0__0__RetryPolicy)
		index := -1
		for allEnums := dafny.Iterate(AwsCryptographyEncryptionSdkTypes.CompanionStruct_NetV4__0__0__RetryPolicy_{}.AllSingletonConstructors()); ; {
			enum, ok := allEnums()
			if ok {
				index++
				if enum.(AwsCryptographyEncryptionSdkTypes.NetV4__0__0__RetryPolicy).Equals(inputEnum) {
					break
				}
			}
		}

		return &u.Values()[index]
	}()
}
