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

package restxml

import (
	"context"
	"github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/schemas"
	smithy "github.com/aws/smithy-go"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

// This example serializes a blob shape in the payload.
//
// In this example, no XML document is synthesized because the payload is not a
// structure or a union type.
func (c *Client) HttpPayloadTraits(ctx context.Context, params *HttpPayloadTraitsInput, optFns ...func(*Options)) (*HttpPayloadTraitsOutput, error) {
	if params == nil {
		params = &HttpPayloadTraitsInput{}
	}

	result, metadata, err := c.invokeOperation(ctx, "HttpPayloadTraits", params, optFns, c.addOperationHttpPayloadTraitsMiddlewares)
	if err != nil {
		return nil, err
	}

	out := result.(*HttpPayloadTraitsOutput)
	out.ResultMetadata = metadata
	return out, nil
}

type HttpPayloadTraitsInput struct {
	Blob []byte

	Foo *string

	noSmithyDocumentSerde
}

func (v *HttpPayloadTraitsInput) Serialize(s smithy.ShapeSerializer) {
	s.WriteStruct(schemas.HttpPayloadTraitsInputOutput)
	v.SerializeMembers(s)
	s.CloseStruct()
}

func (v *HttpPayloadTraitsInput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.Blob != nil {
		s.WriteBlob(schemas.HttpPayloadTraitsInputOutput_blob, v.Blob)
	}
	if v.Foo != nil {
		s.WriteString(schemas.HttpPayloadTraitsInputOutput_foo, *v.Foo)
	}
}
func (v *HttpPayloadTraitsInput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.HttpPayloadTraitsInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.HttpPayloadTraitsInputOutput_blob:
			return d.ReadBlob(schemas.HttpPayloadTraitsInputOutput_blob, &v.Blob)
		case schemas.HttpPayloadTraitsInputOutput_foo:
			v.Foo = new(string)
			return d.ReadString(schemas.HttpPayloadTraitsInputOutput_foo, v.Foo)
		}
		return nil
	})
}

type HttpPayloadTraitsOutput struct {
	Blob []byte

	Foo *string

	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (v *HttpPayloadTraitsOutput) Serialize(s smithy.ShapeSerializer) {
	s.WriteStruct(schemas.HttpPayloadTraitsInputOutput)
	v.SerializeMembers(s)
	s.CloseStruct()
}

func (v *HttpPayloadTraitsOutput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.Blob != nil {
		s.WriteBlob(schemas.HttpPayloadTraitsInputOutput_blob, v.Blob)
	}
	if v.Foo != nil {
		s.WriteString(schemas.HttpPayloadTraitsInputOutput_foo, *v.Foo)
	}
}
func (v *HttpPayloadTraitsOutput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.HttpPayloadTraitsInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.HttpPayloadTraitsInputOutput_blob:
			return d.ReadBlob(schemas.HttpPayloadTraitsInputOutput_blob, &v.Blob)
		case schemas.HttpPayloadTraitsInputOutput_foo:
			v.Foo = new(string)
			return d.ReadString(schemas.HttpPayloadTraitsInputOutput_foo, v.Foo)
		}
		return nil
	})
}
func (c *Client) addOperationHttpPayloadTraitsMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&serializeRequestMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.HttpPayloadTraits, schemas.HttpPayloadTraitsInputOutput, schemas.HttpPayloadTraitsInputOutput)}, middleware.After); err != nil {
		return err
	}
	if err := stack.Deserialize.Add(&deserializeResponseMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.HttpPayloadTraits, schemas.HttpPayloadTraitsInputOutput, schemas.HttpPayloadTraitsInputOutput), output: &HttpPayloadTraitsOutput{}}, middleware.After); err != nil {
		return err
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addComputeContentLength(stack); err != nil {
		return err
	}
	if err = addResolveEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = addComputePayloadSHA256(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack, options); err != nil {
		return err
	}
	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "HttpPayloadTraits"), middleware.Before); err != nil {
		return err
	}
	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addResponseErrorMiddleware(stack); err != nil {
		return err
	}
	if err = addRequestResponseLogging(stack, options); err != nil {
		return err
	}
	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}
