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

package awscryptographyencryptionsdksmithygenerated

import (
	"context"

	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/AwsCryptographyEncryptionSdkTypes"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/ESDK"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/awscryptographyencryptionsdksmithygeneratedtypes"
)

type Client struct {
	DafnyClient AwsCryptographyEncryptionSdkTypes.IAwsEncryptionSdkClient
}

func NewClient(clientConfig awscryptographyencryptionsdksmithygeneratedtypes.AwsEncryptionSdkConfig) (*Client, error) {
	var dafnyConfig = AwsEncryptionSdkConfig_ToDafny(clientConfig)
	var dafny_response = ESDK.Companion_Default___.ESDK(dafnyConfig)
	if dafny_response.Is_Failure() {
		panic("Client construction failed. This should never happen")
	}
	var dafnyClient = dafny_response.Extract().(AwsCryptographyEncryptionSdkTypes.IAwsEncryptionSdkClient)
	client := &Client{dafnyClient}
	return client, nil
}

func (client *Client) Encrypt(ctx context.Context, params awscryptographyencryptionsdksmithygeneratedtypes.EncryptInput) (*awscryptographyencryptionsdksmithygeneratedtypes.EncryptOutput, error) {
	err := params.Validate()
	if err != nil {
		opaqueErr := awscryptographyencryptionsdksmithygeneratedtypes.OpaqueError{
			ErrObject: err,
		}
		return nil, opaqueErr
	}

	var dafny_request AwsCryptographyEncryptionSdkTypes.EncryptInput = EncryptInput_ToDafny(params)
	var dafny_response = client.DafnyClient.Encrypt(dafny_request)

	if dafny_response.Is_Failure() {
		err := dafny_response.Dtor_error().(AwsCryptographyEncryptionSdkTypes.Error)
		return nil, Error_FromDafny(err)
	}
	var native_response = EncryptOutput_FromDafny(dafny_response.Dtor_value().(AwsCryptographyEncryptionSdkTypes.EncryptOutput))
	return &native_response, nil

}

func (client *Client) Decrypt(ctx context.Context, params awscryptographyencryptionsdksmithygeneratedtypes.DecryptInput) (*awscryptographyencryptionsdksmithygeneratedtypes.DecryptOutput, error) {
	err := params.Validate()
	if err != nil {
		opaqueErr := awscryptographyencryptionsdksmithygeneratedtypes.OpaqueError{
			ErrObject: err,
		}
		return nil, opaqueErr
	}

	var dafny_request AwsCryptographyEncryptionSdkTypes.DecryptInput = DecryptInput_ToDafny(params)
	var dafny_response = client.DafnyClient.Decrypt(dafny_request)

	if dafny_response.Is_Failure() {
		err := dafny_response.Dtor_error().(AwsCryptographyEncryptionSdkTypes.Error)
		return nil, Error_FromDafny(err)
	}
	var native_response = DecryptOutput_FromDafny(dafny_response.Dtor_value().(AwsCryptographyEncryptionSdkTypes.DecryptOutput))
	return &native_response, nil

}
