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

package awsrestjson

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

// This example serializes a document as the entire HTTP payload.
func (c *Client) DocumentTypeAsPayload(ctx context.Context, params *DocumentTypeAsPayloadInput, optFns ...func(*Options)) (*DocumentTypeAsPayloadOutput, error) {
	if params == nil {
		params = &DocumentTypeAsPayloadInput{}
	}

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

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

type DocumentTypeAsPayloadInput struct {
	DocumentValue document.Interface

	noSmithyDocumentSerde
}

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

func (v *DocumentTypeAsPayloadInput) SerializeMembers(s smithy.ShapeSerializer) {
	s.WriteDocument(schemas.DocumentTypeAsPayloadInputOutput_documentValue, &smithydocument.Opaque{Value: v.DocumentValue})
}
func (v *DocumentTypeAsPayloadInput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.DocumentTypeAsPayloadInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.DocumentTypeAsPayloadInputOutput_documentValue:
			var dv smithydocument.Value
			if err := d.ReadDocument(schemas.DocumentTypeAsPayloadInputOutput_documentValue, &dv); err != nil {
				return err
			}
			if ov, ok := dv.(smithydocument.Opaque); ok {
				v.DocumentValue = internaldocument.NewDocumentUnmarshaler(ov.Value)
			}
			return nil
		}
		return nil
	})
}

type DocumentTypeAsPayloadOutput struct {
	DocumentValue document.Interface

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

	noSmithyDocumentSerde
}

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

func (v *DocumentTypeAsPayloadOutput) SerializeMembers(s smithy.ShapeSerializer) {
	s.WriteDocument(schemas.DocumentTypeAsPayloadInputOutput_documentValue, &smithydocument.Opaque{Value: v.DocumentValue})
}
func (v *DocumentTypeAsPayloadOutput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.DocumentTypeAsPayloadInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.DocumentTypeAsPayloadInputOutput_documentValue:
			var dv smithydocument.Value
			if err := d.ReadDocument(schemas.DocumentTypeAsPayloadInputOutput_documentValue, &dv); err != nil {
				return err
			}
			if ov, ok := dv.(smithydocument.Opaque); ok {
				v.DocumentValue = internaldocument.NewDocumentUnmarshaler(ov.Value)
			}
			return nil
		}
		return nil
	})
}
func (c *Client) addOperationDocumentTypeAsPayloadMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&serializeRequestMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.DocumentTypeAsPayload, schemas.DocumentTypeAsPayloadInputOutput, schemas.DocumentTypeAsPayloadInputOutput)}, middleware.After); err != nil {
		return err
	}
	if err := stack.Deserialize.Add(&deserializeResponseMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.DocumentTypeAsPayload, schemas.DocumentTypeAsPayloadInputOutput, schemas.DocumentTypeAsPayloadInputOutput), output: &DocumentTypeAsPayloadOutput{}}, 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, "DocumentTypeAsPayload"), 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
}
