import { HttpRequest as __HttpRequest , HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http" ; import { expectBoolean as __expectBoolean , expectString as __expectString } from "@aws-sdk/smithy-client" ; import { Endpoint as __Endpoint , HeaderBag as __HeaderBag , MetadataBearer as __MetadataBearer , ResponseMetadata as __ResponseMetadata , SerdeContext as __SerdeContext , SmithyException as __SmithyException , } from "@aws-sdk/types" ; import { DeleteReportDefinitionCommandInput , DeleteReportDefinitionCommandOutput , } from "../commands/DeleteReportDefinitionCommand" ; import { DescribeReportDefinitionsCommandInput , DescribeReportDefinitionsCommandOutput , } from "../commands/DescribeReportDefinitionsCommand" ; import { ModifyReportDefinitionCommandInput , ModifyReportDefinitionCommandOutput , } from "../commands/ModifyReportDefinitionCommand" ; import { PutReportDefinitionCommandInput , PutReportDefinitionCommandOutput , } from "../commands/PutReportDefinitionCommand" ; import { AdditionalArtifact , DeleteReportDefinitionRequest , DeleteReportDefinitionResponse , DescribeReportDefinitionsRequest , DescribeReportDefinitionsResponse , DuplicateReportNameException , InternalErrorException , ModifyReportDefinitionRequest , ModifyReportDefinitionResponse , PutReportDefinitionRequest , PutReportDefinitionResponse , ReportDefinition , ReportLimitReachedException , SchemaElement , ValidationException , } from "../models/models_0" ; export const serializeAws_json1_1DeleteReportDefinitionCommand = async ( input , context ) : Promise < __HttpRequest > => { const headers = { "content-type" : "application/x-amz-json-1.1" , "x-amz-target" : "AWSOrigamiServiceGatewayService.DeleteReportDefinition" , } ; let body ; body = JSON . stringify ( serializeAws_json1_1DeleteReportDefinitionRequest ( input , context ) ) ; return buildHttpRpcRequest ( context , headers , "/" , undefined , body ) ; } ; export const serializeAws_json1_1DescribeReportDefinitionsCommand = async ( input , context ) : Promise < __HttpRequest > => { const headers = { "content-type" : "application/x-amz-json-1.1" , "x-amz-target" : "AWSOrigamiServiceGatewayService.DescribeReportDefinitions" , } ; let body ; body = JSON . stringify ( serializeAws_json1_1DescribeReportDefinitionsRequest ( input , context ) ) ; return buildHttpRpcRequest ( context , headers , "/" , undefined , body ) ; } ; export const serializeAws_json1_1ModifyReportDefinitionCommand = async ( input , context ) : Promise < __HttpRequest > => { const headers = { "content-type" : "application/x-amz-json-1.1" , "x-amz-target" : "AWSOrigamiServiceGatewayService.ModifyReportDefinition" , } ; let body ; body = JSON . stringify ( serializeAws_json1_1ModifyReportDefinitionRequest ( input , context ) ) ; return buildHttpRpcRequest ( context , headers , "/" , undefined , body ) ; } ; export const serializeAws_json1_1PutReportDefinitionCommand = async ( input , context ) : Promise < __HttpRequest > => { const headers = { "content-type" : "application/x-amz-json-1.1" , "x-amz-target" : "AWSOrigamiServiceGatewayService.PutReportDefinition" , } ; let body ; body = JSON . stringify ( serializeAws_json1_1PutReportDefinitionRequest ( input , context ) ) ; return buildHttpRpcRequest ( context , headers , "/" , undefined , body ) ; } ; export const deserializeAws_json1_1DeleteReportDefinitionCommand = async ( output , context ) : Promise < DeleteReportDefinitionCommandOutput > => { if ( output . statusCode >= 300 ) { return deserializeAws_json1_1DeleteReportDefinitionCommandError ( output , context ) ; } const data = await parseBody ( output . body , context ) ; let contents = { } ; contents = deserializeAws_json1_1DeleteReportDefinitionResponse ( data , context ) ; const response = { $metadata : deserializeMetadata ( output ) , ... contents , } ; return Promise . resolve ( response ) ; } ; const deserializeAws_json1_1DeleteReportDefinitionCommandError = async ( output , context ) : Promise < DeleteReportDefinitionCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalErrorException" : case "com.amazonaws.costandusagereportservice#InternalErrorException" : response = { ... ( await deserializeAws_json1_1InternalErrorExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.costandusagereportservice#ValidationException" : response = { ... ( await deserializeAws_json1_1ValidationExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_json1_1DescribeReportDefinitionsCommand = async ( output , context ) : Promise < DescribeReportDefinitionsCommandOutput > => { if ( output . statusCode >= 300 ) { return deserializeAws_json1_1DescribeReportDefinitionsCommandError ( output , context ) ; } const data = await parseBody ( output . body , context ) ; let contents = { } ; contents = deserializeAws_json1_1DescribeReportDefinitionsResponse ( data , context ) ; const response = { $metadata : deserializeMetadata ( output ) , ... contents , } ; return Promise . resolve ( response ) ; } ; const deserializeAws_json1_1DescribeReportDefinitionsCommandError = async ( output , context ) : Promise < DescribeReportDefinitionsCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalErrorException" : case "com.amazonaws.costandusagereportservice#InternalErrorException" : response = { ... ( await deserializeAws_json1_1InternalErrorExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_json1_1ModifyReportDefinitionCommand = async ( output , context ) : Promise < ModifyReportDefinitionCommandOutput > => { if ( output . statusCode >= 300 ) { return deserializeAws_json1_1ModifyReportDefinitionCommandError ( output , context ) ; } const data = await parseBody ( output . body , context ) ; let contents = { } ; contents = deserializeAws_json1_1ModifyReportDefinitionResponse ( data , context ) ; const response = { $metadata : deserializeMetadata ( output ) , ... contents , } ; return Promise . resolve ( response ) ; } ; const deserializeAws_json1_1ModifyReportDefinitionCommandError = async ( output , context ) : Promise < ModifyReportDefinitionCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalErrorException" : case "com.amazonaws.costandusagereportservice#InternalErrorException" : response = { ... ( await deserializeAws_json1_1InternalErrorExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.costandusagereportservice#ValidationException" : response = { ... ( await deserializeAws_json1_1ValidationExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_json1_1PutReportDefinitionCommand = async ( output , context ) : Promise < PutReportDefinitionCommandOutput > => { if ( output . statusCode >= 300 ) { return deserializeAws_json1_1PutReportDefinitionCommandError ( output , context ) ; } const data = await parseBody ( output . body , context ) ; let contents = { } ; contents = deserializeAws_json1_1PutReportDefinitionResponse ( data , context ) ; const response = { $metadata : deserializeMetadata ( output ) , ... contents , } ; return Promise . resolve ( response ) ; } ; const deserializeAws_json1_1PutReportDefinitionCommandError = async ( output , context ) : Promise < PutReportDefinitionCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "DuplicateReportNameException" : case "com.amazonaws.costandusagereportservice#DuplicateReportNameException" : response = { ... ( await deserializeAws_json1_1DuplicateReportNameExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalErrorException" : case "com.amazonaws.costandusagereportservice#InternalErrorException" : response = { ... ( await deserializeAws_json1_1InternalErrorExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ReportLimitReachedException" : case "com.amazonaws.costandusagereportservice#ReportLimitReachedException" : response = { ... ( await deserializeAws_json1_1ReportLimitReachedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.costandusagereportservice#ValidationException" : response = { ... ( await deserializeAws_json1_1ValidationExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; const deserializeAws_json1_1DuplicateReportNameExceptionResponse = async ( parsedOutput , context ) : Promise < DuplicateReportNameException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1DuplicateReportNameException ( body , context ) ; const contents = { name : "DuplicateReportNameException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const deserializeAws_json1_1InternalErrorExceptionResponse = async ( parsedOutput , context ) : Promise < InternalErrorException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1InternalErrorException ( body , context ) ; const contents = { name : "InternalErrorException" , $fault : "server" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const deserializeAws_json1_1ReportLimitReachedExceptionResponse = async ( parsedOutput , context ) : Promise < ReportLimitReachedException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1ReportLimitReachedException ( body , context ) ; const contents = { name : "ReportLimitReachedException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const deserializeAws_json1_1ValidationExceptionResponse = async ( parsedOutput , context ) : Promise < ValidationException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1ValidationException ( body , context ) ; const contents = { name : "ValidationException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const serializeAws_json1_1AdditionalArtifactList = ( input , context ) : any => { return input . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return entry ; } ) ; } ; const serializeAws_json1_1DeleteReportDefinitionRequest = ( input , context ) : any => { return { ... ( input . ReportName !== undefined && input . ReportName !== null && { ReportName : input . ReportName } ) , } ; } ; const serializeAws_json1_1DescribeReportDefinitionsRequest = ( input , context ) : any => { return { ... ( input . MaxResults !== undefined && input . MaxResults !== null && { MaxResults : input . MaxResults } ) , ... ( input . NextToken !== undefined && input . NextToken !== null && { NextToken : input . NextToken } ) , } ; } ; const serializeAws_json1_1ModifyReportDefinitionRequest = ( input , context ) : any => { return { ... ( input . ReportDefinition !== undefined && input . ReportDefinition !== null && { ReportDefinition : serializeAws_json1_1ReportDefinition ( input . ReportDefinition , context ) , } ) , ... ( input . ReportName !== undefined && input . ReportName !== null && { ReportName : input . ReportName } ) , } ; } ; const serializeAws_json1_1PutReportDefinitionRequest = ( input , context ) : any => { return { ... ( input . ReportDefinition !== undefined && input . ReportDefinition !== null && { ReportDefinition : serializeAws_json1_1ReportDefinition ( input . ReportDefinition , context ) , } ) , } ; } ; const serializeAws_json1_1ReportDefinition = ( input , context ) : any => { return { ... ( input . AdditionalArtifacts !== undefined && input . AdditionalArtifacts !== null && { AdditionalArtifacts : serializeAws_json1_1AdditionalArtifactList ( input . AdditionalArtifacts , context ) , } ) , ... ( input . AdditionalSchemaElements !== undefined && input . AdditionalSchemaElements !== null && { AdditionalSchemaElements : serializeAws_json1_1SchemaElementList ( input . AdditionalSchemaElements , context ) , } ) , ... ( input . BillingViewArn !== undefined && input . BillingViewArn !== null && { BillingViewArn : input . BillingViewArn } ) , ... ( input . Compression !== undefined && input . Compression !== null && { Compression : input . Compression } ) , ... ( input . Format !== undefined && input . Format !== null && { Format : input . Format } ) , ... ( input . RefreshClosedReports !== undefined && input . RefreshClosedReports !== null && { RefreshClosedReports : input . RefreshClosedReports } ) , ... ( input . ReportName !== undefined && input . ReportName !== null && { ReportName : input . ReportName } ) , ... ( input . ReportVersioning !== undefined && input . ReportVersioning !== null && { ReportVersioning : input . ReportVersioning } ) , ... ( input . S3Bucket !== undefined && input . S3Bucket !== null && { S3Bucket : input . S3Bucket } ) , ... ( input . S3Prefix !== undefined && input . S3Prefix !== null && { S3Prefix : input . S3Prefix } ) , ... ( input . S3Region !== undefined && input . S3Region !== null && { S3Region : input . S3Region } ) , ... ( input . TimeUnit !== undefined && input . TimeUnit !== null && { TimeUnit : input . TimeUnit } ) , } ; } ; const serializeAws_json1_1SchemaElementList = ( input , context ) : any => { return input . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return entry ; } ) ; } ; const deserializeAws_json1_1AdditionalArtifactList = ( output , context ) : ( AdditionalArtifact | string ) [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return __expectString ( entry ) as any ; } ) ; } ; const deserializeAws_json1_1DeleteReportDefinitionResponse = ( output , context ) : DeleteReportDefinitionResponse => { return { ResponseMessage : __expectString ( output . ResponseMessage ) , } as any ; } ; const deserializeAws_json1_1DescribeReportDefinitionsResponse = ( output , context ) : DescribeReportDefinitionsResponse => { return { NextToken : __expectString ( output . NextToken ) , ReportDefinitions : output . ReportDefinitions !== undefined && output . ReportDefinitions !== null ? deserializeAws_json1_1ReportDefinitionList ( output . ReportDefinitions , context ) : undefined , } as any ; } ; const deserializeAws_json1_1DuplicateReportNameException = ( output , context ) : DuplicateReportNameException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeAws_json1_1InternalErrorException = ( output , context ) : InternalErrorException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeAws_json1_1ModifyReportDefinitionResponse = ( output , context ) : ModifyReportDefinitionResponse => { return { } as any ; } ; const deserializeAws_json1_1PutReportDefinitionResponse = ( output , context ) : PutReportDefinitionResponse => { return { } as any ; } ; const deserializeAws_json1_1ReportDefinition = ( output , context ) : ReportDefinition => { return { AdditionalArtifacts : output . AdditionalArtifacts !== undefined && output . AdditionalArtifacts !== null ? deserializeAws_json1_1AdditionalArtifactList ( output . AdditionalArtifacts , context ) : undefined , AdditionalSchemaElements : output . AdditionalSchemaElements !== undefined && output . AdditionalSchemaElements !== null ? deserializeAws_json1_1SchemaElementList ( output . AdditionalSchemaElements , context ) : undefined , BillingViewArn : __expectString ( output . BillingViewArn ) , Compression : __expectString ( output . Compression ) , Format : __expectString ( output . Format ) , RefreshClosedReports : __expectBoolean ( output . RefreshClosedReports ) , ReportName : __expectString ( output . ReportName ) , ReportVersioning : __expectString ( output . ReportVersioning ) , S3Bucket : __expectString ( output . S3Bucket ) , S3Prefix : __expectString ( output . S3Prefix ) , S3Region : __expectString ( output . S3Region ) , TimeUnit : __expectString ( output . TimeUnit ) , } as any ; } ; const deserializeAws_json1_1ReportDefinitionList = ( output , context ) : ReportDefinition [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_json1_1ReportDefinition ( entry , context ) ; } ) ; } ; const deserializeAws_json1_1ReportLimitReachedException = ( output , context ) : ReportLimitReachedException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeAws_json1_1SchemaElementList = ( output , context ) : ( SchemaElement | string ) [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return __expectString ( entry ) as any ; } ) ; } ; const deserializeAws_json1_1ValidationException = ( output , context ) : ValidationException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeMetadata = ( output ) : __ResponseMetadata => ( { httpStatusCode : output . statusCode , requestId : output . headers [ "x-amzn-requestid" ] ?? output . headers [ "x-amzn-request-id" ] , extendedRequestId : output . headers [ "x-amz-id-2" ] , cfId : output . headers [ "x-amz-cf-id" ] , } ) ; const collectBody = ( streamBody = new Uint8Array ( ) , context ) : Promise < Uint8Array > => { if ( streamBody instanceof Uint8Array ) { return Promise . resolve ( streamBody ) ; } return context . streamCollector ( streamBody ) || Promise . resolve ( new Uint8Array ( ) ) ; } ; const collectBodyString = ( streamBody , context ) : Promise < string > => collectBody ( streamBody , context ) . then ( ( body ) => context . utf8Encoder ( body ) ) ; const buildHttpRpcRequest = async ( context , headers , path , resolvedHostname , body ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const contents = { protocol , hostname , port , method : "POST" , path : basePath . endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) + path : basePath + path , headers , } ; if ( resolvedHostname !== undefined ) { contents . hostname = resolvedHostname ; } if ( body !== undefined ) { contents . body = body ; } return new __HttpRequest ( contents ) ; } ; const parseBody = ( streamBody , context ) : any => collectBodyString ( streamBody , context ) . then ( ( encoded ) => { if ( encoded . length ) { return JSON . parse ( encoded ) ; } return { } ; } ) ; /**
 * Load an error code for the aws.rest-json-1.1 protocol.
 */ const loadRestJsonErrorCode = ( output , data ) : string => { const findKey = ( object , key ) => Object . keys ( object ) . find ( ( k ) => k . toLowerCase ( ) === key . toLowerCase ( ) ) ; const sanitizeErrorCode = ( rawValue ) : string => { let cleanValue = rawValue ; if ( cleanValue . indexOf ( ":" ) >= 0 ) { cleanValue = cleanValue . split ( ":" ) [ 0 ] ; } if ( cleanValue . indexOf ( "#" ) >= 0 ) { cleanValue = cleanValue . split ( "#" ) [ 1 ] ; } return cleanValue ; } ; const headerKey = findKey ( output . headers , "x-amzn-errortype" ) ; if ( headerKey !== undefined ) { return sanitizeErrorCode ( output . headers [ headerKey ] ) ; } if ( data . code !== undefined ) { return sanitizeErrorCode ( data . code ) ; } if ( data [ "__type" ] !== undefined ) { return sanitizeErrorCode ( data [ "__type" ] ) ; } return "" ; } ;