package smithy

import 

// APIError provides the generic API and protocol agnostic error type all SDK
// generated exception types will implement.
type APIError interface {
	error

	// ErrorCode returns the error code for the API exception.
	ErrorCode() string
	// ErrorMessage returns the error message for the API exception.
	ErrorMessage() string
	// ErrorFault returns the fault for the API exception.
	ErrorFault() ErrorFault
}

// GenericAPIError provides a generic concrete API error type that SDKs can use
// to deserialize error responses into. Should be used for unmodeled or untyped
// errors.
type GenericAPIError struct {
	Code    string
	Message string
	Fault   ErrorFault
}

// ErrorCode returns the error code for the API exception.
func ( *GenericAPIError) () string { return .Code }

// ErrorMessage returns the error message for the API exception.
func ( *GenericAPIError) () string { return .Message }

// ErrorFault returns the fault for the API exception.
func ( *GenericAPIError) () ErrorFault { return .Fault }

func ( *GenericAPIError) () string {
	return fmt.Sprintf("api error %s: %s", .Code, .Message)
}

var _ APIError = (*GenericAPIError)(nil)

// OperationError decorates an underlying error which occurred while invoking
// an operation with names of the operation and API.
type OperationError struct {
	ServiceID     string
	OperationName string
	Err           error
}

// Service returns the name of the API service the error occurred with.
func ( *OperationError) () string { return .ServiceID }

// Operation returns the name of the API operation the error occurred with.
func ( *OperationError) () string { return .OperationName }

// Unwrap returns the nested error if any, or nil.
func ( *OperationError) () error { return .Err }

func ( *OperationError) () string {
	return fmt.Sprintf("operation error %s: %s, %v", .ServiceID, .OperationName, .Err)
}

// DeserializationError provides a wrapper for an error that occurs during
// deserialization.
type DeserializationError struct {
	Err      error //  original error
	Snapshot []byte
}

// Error returns a formatted error for DeserializationError
func ( *DeserializationError) () string {
	const  = "deserialization failed"
	if .Err == nil {
		return 
	}
	return fmt.Sprintf("%s, %v", , .Err)
}

// Unwrap returns the underlying Error in DeserializationError
func ( *DeserializationError) () error { return .Err }

// ErrorFault provides the type for a Smithy API error fault.
type ErrorFault int

// ErrorFault enumeration values
const (
	FaultUnknown ErrorFault = iota
	FaultServer
	FaultClient
)

func ( ErrorFault) () string {
	switch  {
	case FaultServer:
		return "server"
	case FaultClient:
		return "client"
	default:
		return "unknown"
	}
}

// SerializationError represents an error that occurred while attempting to serialize a request
type SerializationError struct {
	Err error // original error
}

// Error returns a formatted error for SerializationError
func ( *SerializationError) () string {
	const  = "serialization failed"
	if .Err == nil {
		return 
	}
	return fmt.Sprintf("%s: %v", , .Err)
}

// Unwrap returns the underlying Error in SerializationError
func ( *SerializationError) () error { return .Err }

// CanceledError is the error that will be returned by an API request that was
// canceled. API operations given a Context may return this error when
// canceled.
type CanceledError struct {
	Err error
}

// CanceledError returns true to satisfy interfaces checking for canceled errors.
func (*CanceledError) () bool { return true }

// Unwrap returns the underlying error, if there was one.
func ( *CanceledError) () error {
	return .Err
}

func ( *CanceledError) () string {
	return fmt.Sprintf("canceled, %v", .Err)
}