// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
#[allow(clippy::unnecessary_wraps)]
pub fn de_invoke_model_http_error(
    _response_status: u16,
    _response_headers: &::aws_smithy_runtime_api::http::Headers,
    _response_body: &[u8],
) -> std::result::Result<crate::operation::invoke_model::InvokeModelOutput, crate::operation::invoke_model::InvokeModelError> {
    #[allow(unused_mut)]
    let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(_response_status, _response_headers, _response_body)
        .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
    generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, _response_headers);
    let generic = generic_builder.build();
    let error_code = match generic.code() {
        Some(code) => code,
        None => return Err(crate::operation::invoke_model::InvokeModelError::unhandled(generic)),
    };

    let _error_message = generic.message().map(|msg| msg.to_owned());
    Err(match error_code {
        "AccessDeniedException" => crate::operation::invoke_model::InvokeModelError::AccessDeniedException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::AccessDeniedExceptionBuilder::default();
                output = crate::protocol_serde::shape_access_denied_exception::de_access_denied_exception_json_err(_response_body, output)
                    .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "InternalServerException" => crate::operation::invoke_model::InvokeModelError::InternalServerException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::InternalServerExceptionBuilder::default();
                output = crate::protocol_serde::shape_internal_server_exception::de_internal_server_exception_json_err(_response_body, output)
                    .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ModelErrorException" => crate::operation::invoke_model::InvokeModelError::ModelErrorException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ModelErrorExceptionBuilder::default();
                output = crate::protocol_serde::shape_model_error_exception::de_model_error_exception_json_err(_response_body, output)
                    .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ModelNotReadyException" => crate::operation::invoke_model::InvokeModelError::ModelNotReadyException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ModelNotReadyExceptionBuilder::default();
                output = crate::protocol_serde::shape_model_not_ready_exception::de_model_not_ready_exception_json_err(_response_body, output)
                    .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ModelTimeoutException" => crate::operation::invoke_model::InvokeModelError::ModelTimeoutException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ModelTimeoutExceptionBuilder::default();
                output = crate::protocol_serde::shape_model_timeout_exception::de_model_timeout_exception_json_err(_response_body, output)
                    .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ResourceNotFoundException" => crate::operation::invoke_model::InvokeModelError::ResourceNotFoundException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ResourceNotFoundExceptionBuilder::default();
                output = crate::protocol_serde::shape_resource_not_found_exception::de_resource_not_found_exception_json_err(_response_body, output)
                    .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ServiceQuotaExceededException" => crate::operation::invoke_model::InvokeModelError::ServiceQuotaExceededException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ServiceQuotaExceededExceptionBuilder::default();
                output = crate::protocol_serde::shape_service_quota_exceeded_exception::de_service_quota_exceeded_exception_json_err(
                    _response_body,
                    output,
                )
                .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ServiceUnavailableException" => crate::operation::invoke_model::InvokeModelError::ServiceUnavailableException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ServiceUnavailableExceptionBuilder::default();
                output =
                    crate::protocol_serde::shape_service_unavailable_exception::de_service_unavailable_exception_json_err(_response_body, output)
                        .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ThrottlingException" => crate::operation::invoke_model::InvokeModelError::ThrottlingException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ThrottlingExceptionBuilder::default();
                output = crate::protocol_serde::shape_throttling_exception::de_throttling_exception_json_err(_response_body, output)
                    .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        "ValidationException" => crate::operation::invoke_model::InvokeModelError::ValidationException({
            #[allow(unused_mut)]
            let mut tmp = {
                #[allow(unused_mut)]
                let mut output = crate::types::error::builders::ValidationExceptionBuilder::default();
                output = crate::protocol_serde::shape_validation_exception::de_validation_exception_json_err(_response_body, output)
                    .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?;
                let output = output.meta(generic);
                output.build()
            };
            if tmp.message.is_none() {
                tmp.message = _error_message;
            }
            tmp
        }),
        _ => crate::operation::invoke_model::InvokeModelError::generic(generic),
    })
}

#[allow(clippy::unnecessary_wraps)]
pub fn de_invoke_model_http_response(
    _response_status: u16,
    _response_headers: &::aws_smithy_runtime_api::http::Headers,
    _response_body: &[u8],
) -> std::result::Result<crate::operation::invoke_model::InvokeModelOutput, crate::operation::invoke_model::InvokeModelError> {
    Ok({
        #[allow(unused_mut)]
        let mut output = crate::operation::invoke_model::builders::InvokeModelOutputBuilder::default();
        output = output.set_body(crate::protocol_serde::shape_invoke_model_output::de_body_payload(_response_body)?);
        output = output.set_content_type(
            crate::protocol_serde::shape_invoke_model_output::de_content_type_header(_response_headers)
                .map_err(|_| crate::operation::invoke_model::InvokeModelError::unhandled("Failed to parse contentType from header `Content-Type"))?,
        );
        output = output.set_performance_config_latency(
            crate::protocol_serde::shape_invoke_model_output::de_performance_config_latency_header(_response_headers).map_err(|_| {
                crate::operation::invoke_model::InvokeModelError::unhandled(
                    "Failed to parse performanceConfigLatency from header `X-Amzn-Bedrock-PerformanceConfig-Latency",
                )
            })?,
        );
        output = output.set_service_tier(
            crate::protocol_serde::shape_invoke_model_output::de_service_tier_header(_response_headers).map_err(|_| {
                crate::operation::invoke_model::InvokeModelError::unhandled("Failed to parse serviceTier from header `X-Amzn-Bedrock-Service-Tier")
            })?,
        );
        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
        crate::serde_util::invoke_model_output_output_correct_errors(output)
            .build()
            .map_err(crate::operation::invoke_model::InvokeModelError::unhandled)?
    })
}

pub fn ser_invoke_model_headers(
    input: &crate::operation::invoke_model::InvokeModelInput,
    mut builder: ::http_1x::request::Builder,
) -> std::result::Result<::http_1x::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
    if let ::std::option::Option::Some(inner_1) = &input.content_type {
        let formatted_2 = inner_1.as_str();
        let header_value = formatted_2;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "content_type",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("Content-Type", header_value);
    }
    if let ::std::option::Option::Some(inner_3) = &input.accept {
        let formatted_4 = inner_3.as_str();
        let header_value = formatted_4;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "accept",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("Accept", header_value);
    }
    if let ::std::option::Option::Some(inner_5) = &input.trace {
        let formatted_6 = inner_5.as_str();
        let header_value = formatted_6;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "trace",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("X-Amzn-Bedrock-Trace", header_value);
    }
    if let ::std::option::Option::Some(inner_7) = &input.guardrail_identifier {
        let formatted_8 = inner_7.as_str();
        let header_value = formatted_8;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "guardrail_identifier",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("X-Amzn-Bedrock-GuardrailIdentifier", header_value);
    }
    if let ::std::option::Option::Some(inner_9) = &input.guardrail_version {
        let formatted_10 = inner_9.as_str();
        let header_value = formatted_10;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "guardrail_version",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("X-Amzn-Bedrock-GuardrailVersion", header_value);
    }
    if let ::std::option::Option::Some(inner_11) = &input.performance_config_latency {
        let formatted_12 = inner_11.as_str();
        let header_value = formatted_12;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "performance_config_latency",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("X-Amzn-Bedrock-PerformanceConfig-Latency", header_value);
    }
    if let ::std::option::Option::Some(inner_13) = &input.service_tier {
        let formatted_14 = inner_13.as_str();
        let header_value = formatted_14;
        let header_value: ::http_1x::HeaderValue = header_value.parse().map_err(|err| {
            ::aws_smithy_types::error::operation::BuildError::invalid_field(
                "service_tier",
                format!("`{}` cannot be used as a header value: {}", &header_value, err),
            )
        })?;
        builder = builder.header("X-Amzn-Bedrock-Service-Tier", header_value);
    }
    Ok(builder)
}
