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

package awsrestjson

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

// This examples serializes a streaming media-typed blob shape in the request body.
//
// This examples uses a @mediaType trait on the payload to force a custom
// content-type to be serialized.
func (c *Client) StreamingTraitsWithMediaType(ctx context.Context, params *StreamingTraitsWithMediaTypeInput, optFns ...func(*Options)) (*StreamingTraitsWithMediaTypeOutput, error) {
	if params == nil {
		params = &StreamingTraitsWithMediaTypeInput{}
	}

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

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

type StreamingTraitsWithMediaTypeInput struct {

	// This value conforms to the media type: text/plain
	Blob io.Reader

	Foo *string

	noSmithyDocumentSerde
}

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

func (v *StreamingTraitsWithMediaTypeInput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.Foo != nil {
		s.WriteString(schemas.StreamingTraitsWithMediaTypeInputOutput_foo, *v.Foo)
	}
}
func (v *StreamingTraitsWithMediaTypeInput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.StreamingTraitsWithMediaTypeInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.StreamingTraitsWithMediaTypeInputOutput_foo:
			v.Foo = new(string)
			return d.ReadString(schemas.StreamingTraitsWithMediaTypeInputOutput_foo, v.Foo)
		}
		return nil
	})
}
func (v *StreamingTraitsWithMediaTypeInput) GetPayloadStream() io.Reader { return v.Blob }

var _ smithy.StreamingInput = (*StreamingTraitsWithMediaTypeInput)(nil)

func (v *StreamingTraitsWithMediaTypeInput) SetPayloadStream(r io.ReadCloser) { v.Blob = r }

var _ smithy.StreamingOutput = (*StreamingTraitsWithMediaTypeInput)(nil)

type StreamingTraitsWithMediaTypeOutput struct {

	// This value conforms to the media type: text/plain
	Blob io.ReadCloser

	Foo *string

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

	noSmithyDocumentSerde
}

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

func (v *StreamingTraitsWithMediaTypeOutput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.Foo != nil {
		s.WriteString(schemas.StreamingTraitsWithMediaTypeInputOutput_foo, *v.Foo)
	}
}
func (v *StreamingTraitsWithMediaTypeOutput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.StreamingTraitsWithMediaTypeInputOutput, func(s *smithy.Schema) error {
		switch s {
		case schemas.StreamingTraitsWithMediaTypeInputOutput_foo:
			v.Foo = new(string)
			return d.ReadString(schemas.StreamingTraitsWithMediaTypeInputOutput_foo, v.Foo)
		}
		return nil
	})
}
func (v *StreamingTraitsWithMediaTypeOutput) GetPayloadStream() io.Reader { return v.Blob }

var _ smithy.StreamingInput = (*StreamingTraitsWithMediaTypeOutput)(nil)

func (v *StreamingTraitsWithMediaTypeOutput) SetPayloadStream(r io.ReadCloser) { v.Blob = r }

var _ smithy.StreamingOutput = (*StreamingTraitsWithMediaTypeOutput)(nil)

func (c *Client) addOperationStreamingTraitsWithMediaTypeMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&serializeRequestMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.StreamingTraitsWithMediaType, schemas.StreamingTraitsWithMediaTypeInputOutput, schemas.StreamingTraitsWithMediaTypeInputOutput)}, middleware.After); err != nil {
		return err
	}
	if err := stack.Deserialize.Add(&deserializeResponseMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.StreamingTraitsWithMediaType, schemas.StreamingTraitsWithMediaTypeInputOutput, schemas.StreamingTraitsWithMediaTypeInputOutput), output: &StreamingTraitsWithMediaTypeOutput{}}, 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 = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "StreamingTraitsWithMediaType"), 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
}
