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

package awsrestjson

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

// This operation uses unions for inputs and outputs.
func (c *Client) JsonUnions(ctx context.Context, params *JsonUnionsInput, optFns ...func(*Options)) (*JsonUnionsOutput, error) {
	if params == nil {
		params = &JsonUnionsInput{}
	}

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

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

// A shared structure that contains a single union member.
type JsonUnionsInput struct {

	// A union with a representative set of types for members.
	Contents types.MyUnion

	noSmithyDocumentSerde
}

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

func (v *JsonUnionsInput) SerializeMembers(s smithy.ShapeSerializer) {
	serializeMyUnion(s, schemas.UnionInputOutput_contents, v.Contents)
}
func (v *JsonUnionsInput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.UnionInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.UnionInputOutput_contents:
			return deserializeMyUnion(d, schemas.UnionInputOutput_contents, &v.Contents)
		}
		return nil
	})
}

// A shared structure that contains a single union member.
type JsonUnionsOutput struct {

	// A union with a representative set of types for members.
	Contents types.MyUnion

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

	noSmithyDocumentSerde
}

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

func (v *JsonUnionsOutput) SerializeMembers(s smithy.ShapeSerializer) {
	serializeMyUnion(s, schemas.UnionInputOutput_contents, v.Contents)
}
func (v *JsonUnionsOutput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.UnionInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.UnionInputOutput_contents:
			return deserializeMyUnion(d, schemas.UnionInputOutput_contents, &v.Contents)
		}
		return nil
	})
}
func (c *Client) addOperationJsonUnionsMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&serializeRequestMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.JsonUnions, schemas.UnionInputOutput, schemas.UnionInputOutput)}, middleware.After); err != nil {
		return err
	}
	if err := stack.Deserialize.Add(&deserializeResponseMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.JsonUnions, schemas.UnionInputOutput, schemas.UnionInputOutput), output: &JsonUnionsOutput{}}, 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, "JsonUnions"), 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
}
