package checksum

import (
	

	
)

// setupChecksumContext is the initial middleware that looks up the input
// used to configure checksum behavior. This middleware must be executed before
// input validation step or any other checksum middleware.
type setupInputContext struct {
	// GetAlgorithm is a function to get the checksum algorithm of the
	// input payload from the input parameters.
	//
	// Given the input parameter value, the function must return the algorithm
	// and true, or false if no algorithm is specified.
	GetAlgorithm func(interface{}) (string, bool)
}

// ID for the middleware
func ( *setupInputContext) () string {
	return "AWSChecksum:SetupInputContext"
}

// HandleInitialize initialization middleware that setups up the checksum
// context based on the input parameters provided in the stack.
func ( *setupInputContext) (
	 context.Context,  middleware.InitializeInput,  middleware.InitializeHandler,
) (
	 middleware.InitializeOutput,  middleware.Metadata,  error,
) {
	// Check if validation algorithm is specified.
	if .GetAlgorithm != nil {
		// check is input resource has a checksum algorithm
		,  := .GetAlgorithm(.Parameters)
		if  && len() != 0 {
			 = setContextInputAlgorithm(, )
		}
	}

	return .HandleInitialize(, )
}

// inputAlgorithmKey is the key set on context used to identify, retrieves the
// request checksum algorithm if present on the context.
type inputAlgorithmKey struct{}

// setContextInputAlgorithm sets the request checksum algorithm on the context.
//
// Scoped to stack values.
func ( context.Context,  string) context.Context {
	return middleware.WithStackValue(, inputAlgorithmKey{}, )
}

// getContextInputAlgorithm returns the checksum algorithm from the context if
// one was specified. Empty string is returned if one is not specified.
//
// Scoped to stack values.
func ( context.Context) ( string) {
	, _ = middleware.GetStackValue(, inputAlgorithmKey{}).(string)
	return 
}

type setupOutputContext struct {
	// GetValidationMode is a function to get the checksum validation
	// mode of the output payload from the input parameters.
	//
	// Given the input parameter value, the function must return the validation
	// mode and true, or false if no mode is specified.
	GetValidationMode func(interface{}) (string, bool)
}

// ID for the middleware
func ( *setupOutputContext) () string {
	return "AWSChecksum:SetupOutputContext"
}

// HandleInitialize initialization middleware that setups up the checksum
// context based on the input parameters provided in the stack.
func ( *setupOutputContext) (
	 context.Context,  middleware.InitializeInput,  middleware.InitializeHandler,
) (
	 middleware.InitializeOutput,  middleware.Metadata,  error,
) {
	// Check if validation mode is specified.
	if .GetValidationMode != nil {
		// check is input resource has a checksum algorithm
		,  := .GetValidationMode(.Parameters)
		if  && len() != 0 {
			 = setContextOutputValidationMode(, )
		}
	}

	return .HandleInitialize(, )
}

// outputValidationModeKey is the key set on context used to identify if
// output checksum validation is enabled.
type outputValidationModeKey struct{}

// setContextOutputValidationMode sets the request checksum
// algorithm on the context.
//
// Scoped to stack values.
func ( context.Context,  string) context.Context {
	return middleware.WithStackValue(, outputValidationModeKey{}, )
}

// getContextOutputValidationMode returns response checksum validation state,
// if one was specified. Empty string is returned if one is not specified.
//
// Scoped to stack values.
func ( context.Context) ( string) {
	, _ = middleware.GetStackValue(, outputValidationModeKey{}).(string)
	return 
}