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

package restxml

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

// This example serializes a union in the payload.
func (c *Client) HttpPayloadWithUnion(ctx context.Context, params *HttpPayloadWithUnionInput, optFns ...func(*Options)) (*HttpPayloadWithUnionOutput, error) {
	if params == nil {
		params = &HttpPayloadWithUnionInput{}
	}

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

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

type HttpPayloadWithUnionInput struct {
	Nested types.UnionPayload

	noSmithyDocumentSerde
}

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

func (v *HttpPayloadWithUnionInput) SerializeMembers(s smithy.ShapeSerializer) {
	serializeUnionPayload(s, schemas.HttpPayloadWithUnionInputOutput_nested, v.Nested)
}
func (v *HttpPayloadWithUnionInput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.HttpPayloadWithUnionInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.HttpPayloadWithUnionInputOutput_nested:
			return deserializeUnionPayload(d, schemas.HttpPayloadWithUnionInputOutput_nested, &v.Nested)
		}
		return nil
	})
}

type HttpPayloadWithUnionOutput struct {
	Nested types.UnionPayload

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

	noSmithyDocumentSerde
}

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

func (v *HttpPayloadWithUnionOutput) SerializeMembers(s smithy.ShapeSerializer) {
	serializeUnionPayload(s, schemas.HttpPayloadWithUnionInputOutput_nested, v.Nested)
}
func (v *HttpPayloadWithUnionOutput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.HttpPayloadWithUnionInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.HttpPayloadWithUnionInputOutput_nested:
			return deserializeUnionPayload(d, schemas.HttpPayloadWithUnionInputOutput_nested, &v.Nested)
		}
		return nil
	})
}
func (c *Client) addOperationHttpPayloadWithUnionMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&serializeRequestMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.HttpPayloadWithUnion, schemas.HttpPayloadWithUnionInputOutput, schemas.HttpPayloadWithUnionInputOutput)}, middleware.After); err != nil {
		return err
	}
	if err := stack.Deserialize.Add(&deserializeResponseMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.HttpPayloadWithUnion, schemas.HttpPayloadWithUnionInputOutput, schemas.HttpPayloadWithUnionInputOutput), output: &HttpPayloadWithUnionOutput{}}, 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); 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, "HttpPayloadWithUnion"), 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
}
