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

package comprehendmedical

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

// InferICD10CM detects medical conditions as entities listed in a patient record
// and links those entities to normalized concept identifiers in the ICD-10-CM
// knowledge base from the Centers for Disease Control. Amazon Comprehend Medical
// only detects medical entities in English language texts.
func (c *Client) InferICD10CM(ctx context.Context, params *InferICD10CMInput, optFns ...func(*Options)) (*InferICD10CMOutput, error) {
	if params == nil {
		params = &InferICD10CMInput{}
	}

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

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

type InferICD10CMInput struct {

	// The input text used for analysis.
	//
	// This member is required.
	Text *string

	noSmithyDocumentSerde
}

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

func (v *InferICD10CMInput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.Text != nil {
		s.WriteString(schemas.InferICD10CMRequest_Text, *v.Text)
	}
}

type InferICD10CMOutput struct {

	// The medical conditions detected in the text linked to ICD-10-CM concepts. If
	// the action is successful, the service sends back an HTTP 200 response, as well
	// as the entities detected.
	//
	// This member is required.
	Entities []types.ICD10CMEntity

	// The version of the model used to analyze the documents, in the format n.n.n You
	// can use this information to track the model used for a particular batch of
	// documents.
	ModelVersion *string

	// If the result of the previous request to InferICD10CM was truncated, include
	// the PaginationToken to fetch the next page of medical condition entities.
	PaginationToken *string

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

	noSmithyDocumentSerde
}

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

func (v *InferICD10CMOutput) SerializeMembers(s smithy.ShapeSerializer) {
	serializeICD10CMEntityList(s, schemas.InferICD10CMResponse_Entities, v.Entities)
	if v.ModelVersion != nil {
		s.WriteString(schemas.InferICD10CMResponse_ModelVersion, *v.ModelVersion)
	}
	if v.PaginationToken != nil {
		s.WriteString(schemas.InferICD10CMResponse_PaginationToken, *v.PaginationToken)
	}
}
func (v *InferICD10CMOutput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.InferICD10CMResponse, func(s *smithy.Schema) error {
		switch s {
		case schemas.InferICD10CMResponse_Entities:
			return deserializeICD10CMEntityList(d, schemas.InferICD10CMResponse_Entities, &v.Entities)
		case schemas.InferICD10CMResponse_ModelVersion:
			v.ModelVersion = new(string)
			return d.ReadString(schemas.InferICD10CMResponse_ModelVersion, v.ModelVersion)
		case schemas.InferICD10CMResponse_PaginationToken:
			v.PaginationToken = new(string)
			return d.ReadString(schemas.InferICD10CMResponse_PaginationToken, v.PaginationToken)
		}
		return nil
	})
}
func (c *Client) addOperationInferICD10CMMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&serializeRequestMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.InferICD10CM, schemas.InferICD10CMRequest, schemas.InferICD10CMResponse)}, middleware.After); err != nil {
		return err
	}
	if err := stack.Deserialize.Add(&deserializeResponseMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.InferICD10CM, schemas.InferICD10CMRequest, schemas.InferICD10CMResponse), output: &InferICD10CMOutput{}}, 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 = addUserAgentFeatureProtocolRPCV2CBOR(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpInferICD10CMValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "InferICD10CM"), 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
}
