import { HttpRequest as __HttpRequest , HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http" ; import { expectBoolean as __expectBoolean , expectInt32 as __expectInt32 , expectLong as __expectLong , expectNonNull as __expectNonNull , expectNumber as __expectNumber , expectObject as __expectObject , expectString as __expectString , extendedEncodeURIComponent as __extendedEncodeURIComponent , parseEpochTimestamp as __parseEpochTimestamp , } from "@aws-sdk/smithy-client" ; import { Endpoint as __Endpoint , MetadataBearer as __MetadataBearer , ResponseMetadata as __ResponseMetadata , SerdeContext as __SerdeContext , SmithyException as __SmithyException , } from "@aws-sdk/types" ; import { v4 as generateIdempotencyToken } from "uuid" ; import { CancelTaskCommandInput , CancelTaskCommandOutput } from "../commands/CancelTaskCommand" ; import { CreateTaskCommandInput , CreateTaskCommandOutput } from "../commands/CreateTaskCommand" ; import { DescribeDeviceCommandInput , DescribeDeviceCommandOutput } from "../commands/DescribeDeviceCommand" ; import { DescribeDeviceEc2InstancesCommandInput , DescribeDeviceEc2InstancesCommandOutput , } from "../commands/DescribeDeviceEc2InstancesCommand" ; import { DescribeExecutionCommandInput , DescribeExecutionCommandOutput } from "../commands/DescribeExecutionCommand" ; import { DescribeTaskCommandInput , DescribeTaskCommandOutput } from "../commands/DescribeTaskCommand" ; import { ListDeviceResourcesCommandInput , ListDeviceResourcesCommandOutput , } from "../commands/ListDeviceResourcesCommand" ; import { ListDevicesCommandInput , ListDevicesCommandOutput } from "../commands/ListDevicesCommand" ; import { ListExecutionsCommandInput , ListExecutionsCommandOutput } from "../commands/ListExecutionsCommand" ; import { ListTagsForResourceCommandInput , ListTagsForResourceCommandOutput , } from "../commands/ListTagsForResourceCommand" ; import { ListTasksCommandInput , ListTasksCommandOutput } from "../commands/ListTasksCommand" ; import { TagResourceCommandInput , TagResourceCommandOutput } from "../commands/TagResourceCommand" ; import { UntagResourceCommandInput , UntagResourceCommandOutput } from "../commands/UntagResourceCommand" ; import { AccessDeniedException , Capacity , Command , CpuOptions , DeviceSummary , EbsInstanceBlockDevice , ExecutionSummary , Instance , InstanceBlockDeviceMapping , InstanceState , InstanceSummary , InternalServerException , PhysicalNetworkInterface , Reboot , ResourceNotFoundException , ResourceSummary , SecurityGroupIdentifier , ServiceQuotaExceededException , SoftwareInformation , TaskSummary , ThrottlingException , Unlock , ValidationException , } from "../models/models_0" ; export const serializeAws_restJson1CancelTaskCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/task/{taskId}/cancel" ; if ( input . taskId !== undefined ) { const labelValue = input . taskId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: taskId." ) ; } resolvedPath = resolvedPath . replace ( "{taskId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: taskId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1CreateTaskCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , } ; const resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/task" ; let body ; body = JSON . stringify ( { clientToken : input . clientToken ?? generateIdempotencyToken ( ) , ... ( input . command !== undefined && input . command !== null && { command : serializeAws_restJson1Command ( input . command , context ) } ) , ... ( input . description !== undefined && input . description !== null && { description : input . description } ) , ... ( input . tags !== undefined && input . tags !== null && { tags : serializeAws_restJson1TagMap ( input . tags , context ) } ) , ... ( input . targets !== undefined && input . targets !== null && { targets : serializeAws_restJson1TargetList ( input . targets , context ) } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1DescribeDeviceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/managed-device/{managedDeviceId}/describe" ; if ( input . managedDeviceId !== undefined ) { const labelValue = input . managedDeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: managedDeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{managedDeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: managedDeviceId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1DescribeDeviceEc2InstancesCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/managed-device/{managedDeviceId}/resources/ec2/describe" ; if ( input . managedDeviceId !== undefined ) { const labelValue = input . managedDeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: managedDeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{managedDeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: managedDeviceId." ) ; } let body ; body = JSON . stringify ( { ... ( input . instanceIds !== undefined && input . instanceIds !== null && { instanceIds : serializeAws_restJson1InstanceIdsList ( input . instanceIds , context ) } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1DescribeExecutionCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/task/{taskId}/execution/{managedDeviceId}" ; if ( input . taskId !== undefined ) { const labelValue = input . taskId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: taskId." ) ; } resolvedPath = resolvedPath . replace ( "{taskId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: taskId." ) ; } if ( input . managedDeviceId !== undefined ) { const labelValue = input . managedDeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: managedDeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{managedDeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: managedDeviceId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1DescribeTaskCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/task/{taskId}" ; if ( input . taskId !== undefined ) { const labelValue = input . taskId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: taskId." ) ; } resolvedPath = resolvedPath . replace ( "{taskId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: taskId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1ListDeviceResourcesCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/managed-device/{managedDeviceId}/resources" ; if ( input . managedDeviceId !== undefined ) { const labelValue = input . managedDeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: managedDeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{managedDeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: managedDeviceId." ) ; } const query = { ... ( input . type !== undefined && { type : input . type } ) , ... ( input . maxResults !== undefined && { maxResults : input . maxResults . toString ( ) } ) , ... ( input . nextToken !== undefined && { nextToken : input . nextToken } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , query , body , } ) ; } ; export const serializeAws_restJson1ListDevicesCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; const resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/managed-devices" ; const query = { ... ( input . jobId !== undefined && { jobId : input . jobId } ) , ... ( input . maxResults !== undefined && { maxResults : input . maxResults . toString ( ) } ) , ... ( input . nextToken !== undefined && { nextToken : input . nextToken } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , query , body , } ) ; } ; export const serializeAws_restJson1ListExecutionsCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; const resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/executions" ; const query = { ... ( input . taskId !== undefined && { taskId : input . taskId } ) , ... ( input . state !== undefined && { state : input . state } ) , ... ( input . maxResults !== undefined && { maxResults : input . maxResults . toString ( ) } ) , ... ( input . nextToken !== undefined && { nextToken : input . nextToken } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , query , body , } ) ; } ; export const serializeAws_restJson1ListTagsForResourceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/tags/{resourceArn}" ; if ( input . resourceArn !== undefined ) { const labelValue = input . resourceArn ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: resourceArn." ) ; } resolvedPath = resolvedPath . replace ( "{resourceArn}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: resourceArn." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1ListTasksCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; const resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/tasks" ; const query = { ... ( input . state !== undefined && { state : input . state } ) , ... ( input . maxResults !== undefined && { maxResults : input . maxResults . toString ( ) } ) , ... ( input . nextToken !== undefined && { nextToken : input . nextToken } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , query , body , } ) ; } ; export const serializeAws_restJson1TagResourceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/tags/{resourceArn}" ; if ( input . resourceArn !== undefined ) { const labelValue = input . resourceArn ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: resourceArn." ) ; } resolvedPath = resolvedPath . replace ( "{resourceArn}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: resourceArn." ) ; } let body ; body = JSON . stringify ( { ... ( input . tags !== undefined && input . tags !== null && { tags : serializeAws_restJson1TagMap ( input . tags , context ) } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1UntagResourceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/tags/{resourceArn}" ; if ( input . resourceArn !== undefined ) { const labelValue = input . resourceArn ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: resourceArn." ) ; } resolvedPath = resolvedPath . replace ( "{resourceArn}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: resourceArn." ) ; } const query = { ... ( input . tagKeys !== undefined && { tagKeys : ( input . tagKeys || [ ] ) . map ( ( _entry ) => _entry as any ) } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "DELETE" , headers , path : resolvedPath , query , body , } ) ; } ; export const deserializeAws_restJson1CancelTaskCommand = async ( output , context ) : Promise < CancelTaskCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1CancelTaskCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , taskId : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . taskId !== undefined && data . taskId !== null ) { contents . taskId = __expectString ( data . taskId ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1CancelTaskCommandError = async ( output , context ) : Promise < CancelTaskCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1CreateTaskCommand = async ( output , context ) : Promise < CreateTaskCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1CreateTaskCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , taskArn : undefined , taskId : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . taskArn !== undefined && data . taskArn !== null ) { contents . taskArn = __expectString ( data . taskArn ) ; } if ( data . taskId !== undefined && data . taskId !== null ) { contents . taskId = __expectString ( data . taskId ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1CreateTaskCommandError = async ( output , context ) : Promise < CreateTaskCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ServiceQuotaExceededException" : case "com.amazonaws.snowdevicemanagement#ServiceQuotaExceededException" : response = { ... ( await deserializeAws_restJson1ServiceQuotaExceededExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1DescribeDeviceCommand = async ( output , context ) : Promise < DescribeDeviceCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1DescribeDeviceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , associatedWithJob : undefined , deviceCapacities : undefined , deviceState : undefined , deviceType : undefined , lastReachedOutAt : undefined , lastUpdatedAt : undefined , managedDeviceArn : undefined , managedDeviceId : undefined , physicalNetworkInterfaces : undefined , software : undefined , tags : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . associatedWithJob !== undefined && data . associatedWithJob !== null ) { contents . associatedWithJob = __expectString ( data . associatedWithJob ) ; } if ( data . deviceCapacities !== undefined && data . deviceCapacities !== null ) { contents . deviceCapacities = deserializeAws_restJson1CapacityList ( data . deviceCapacities , context ) ; } if ( data . deviceState !== undefined && data . deviceState !== null ) { contents . deviceState = __expectString ( data . deviceState ) ; } if ( data . deviceType !== undefined && data . deviceType !== null ) { contents . deviceType = __expectString ( data . deviceType ) ; } if ( data . lastReachedOutAt !== undefined && data . lastReachedOutAt !== null ) { contents . lastReachedOutAt = __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( data . lastReachedOutAt ) ) ) ; } if ( data . lastUpdatedAt !== undefined && data . lastUpdatedAt !== null ) { contents . lastUpdatedAt = __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( data . lastUpdatedAt ) ) ) ; } if ( data . managedDeviceArn !== undefined && data . managedDeviceArn !== null ) { contents . managedDeviceArn = __expectString ( data . managedDeviceArn ) ; } if ( data . managedDeviceId !== undefined && data . managedDeviceId !== null ) { contents . managedDeviceId = __expectString ( data . managedDeviceId ) ; } if ( data . physicalNetworkInterfaces !== undefined && data . physicalNetworkInterfaces !== null ) { contents . physicalNetworkInterfaces = deserializeAws_restJson1PhysicalNetworkInterfaceList ( data . physicalNetworkInterfaces , context ) ; } if ( data . software !== undefined && data . software !== null ) { contents . software = deserializeAws_restJson1SoftwareInformation ( data . software , context ) ; } if ( data . tags !== undefined && data . tags !== null ) { contents . tags = deserializeAws_restJson1TagMap ( data . tags , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1DescribeDeviceCommandError = async ( output , context ) : Promise < DescribeDeviceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1DescribeDeviceEc2InstancesCommand = async ( output , context ) : Promise < DescribeDeviceEc2InstancesCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1DescribeDeviceEc2InstancesCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , instances : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . instances !== undefined && data . instances !== null ) { contents . instances = deserializeAws_restJson1InstanceSummaryList ( data . instances , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1DescribeDeviceEc2InstancesCommandError = async ( output , context ) : Promise < DescribeDeviceEc2InstancesCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1DescribeExecutionCommand = async ( output , context ) : Promise < DescribeExecutionCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1DescribeExecutionCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , executionId : undefined , lastUpdatedAt : undefined , managedDeviceId : undefined , startedAt : undefined , state : undefined , taskId : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . executionId !== undefined && data . executionId !== null ) { contents . executionId = __expectString ( data . executionId ) ; } if ( data . lastUpdatedAt !== undefined && data . lastUpdatedAt !== null ) { contents . lastUpdatedAt = __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( data . lastUpdatedAt ) ) ) ; } if ( data . managedDeviceId !== undefined && data . managedDeviceId !== null ) { contents . managedDeviceId = __expectString ( data . managedDeviceId ) ; } if ( data . startedAt !== undefined && data . startedAt !== null ) { contents . startedAt = __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( data . startedAt ) ) ) ; } if ( data . state !== undefined && data . state !== null ) { contents . state = __expectString ( data . state ) ; } if ( data . taskId !== undefined && data . taskId !== null ) { contents . taskId = __expectString ( data . taskId ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1DescribeExecutionCommandError = async ( output , context ) : Promise < DescribeExecutionCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1DescribeTaskCommand = async ( output , context ) : Promise < DescribeTaskCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1DescribeTaskCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , completedAt : undefined , createdAt : undefined , description : undefined , lastUpdatedAt : undefined , state : undefined , tags : undefined , targets : undefined , taskArn : undefined , taskId : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . completedAt !== undefined && data . completedAt !== null ) { contents . completedAt = __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( data . completedAt ) ) ) ; } if ( data . createdAt !== undefined && data . createdAt !== null ) { contents . createdAt = __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( data . createdAt ) ) ) ; } if ( data . description !== undefined && data . description !== null ) { contents . description = __expectString ( data . description ) ; } if ( data . lastUpdatedAt !== undefined && data . lastUpdatedAt !== null ) { contents . lastUpdatedAt = __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( data . lastUpdatedAt ) ) ) ; } if ( data . state !== undefined && data . state !== null ) { contents . state = __expectString ( data . state ) ; } if ( data . tags !== undefined && data . tags !== null ) { contents . tags = deserializeAws_restJson1TagMap ( data . tags , context ) ; } if ( data . targets !== undefined && data . targets !== null ) { contents . targets = deserializeAws_restJson1TargetList ( data . targets , context ) ; } if ( data . taskArn !== undefined && data . taskArn !== null ) { contents . taskArn = __expectString ( data . taskArn ) ; } if ( data . taskId !== undefined && data . taskId !== null ) { contents . taskId = __expectString ( data . taskId ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1DescribeTaskCommandError = async ( output , context ) : Promise < DescribeTaskCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1ListDeviceResourcesCommand = async ( output , context ) : Promise < ListDeviceResourcesCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ListDeviceResourcesCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , nextToken : undefined , resources : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . nextToken !== undefined && data . nextToken !== null ) { contents . nextToken = __expectString ( data . nextToken ) ; } if ( data . resources !== undefined && data . resources !== null ) { contents . resources = deserializeAws_restJson1ResourceSummaryList ( data . resources , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ListDeviceResourcesCommandError = async ( output , context ) : Promise < ListDeviceResourcesCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1ListDevicesCommand = async ( output , context ) : Promise < ListDevicesCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ListDevicesCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , devices : undefined , nextToken : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . devices !== undefined && data . devices !== null ) { contents . devices = deserializeAws_restJson1DeviceSummaryList ( data . devices , context ) ; } if ( data . nextToken !== undefined && data . nextToken !== null ) { contents . nextToken = __expectString ( data . nextToken ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ListDevicesCommandError = async ( output , context ) : Promise < ListDevicesCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1ListExecutionsCommand = async ( output , context ) : Promise < ListExecutionsCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ListExecutionsCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , executions : undefined , nextToken : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . executions !== undefined && data . executions !== null ) { contents . executions = deserializeAws_restJson1ExecutionSummaryList ( data . executions , context ) ; } if ( data . nextToken !== undefined && data . nextToken !== null ) { contents . nextToken = __expectString ( data . nextToken ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ListExecutionsCommandError = async ( output , context ) : Promise < ListExecutionsCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1ListTagsForResourceCommand = async ( output , context ) : Promise < ListTagsForResourceCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ListTagsForResourceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , tags : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . tags !== undefined && data . tags !== null ) { contents . tags = deserializeAws_restJson1TagMap ( data . tags , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ListTagsForResourceCommandError = async ( output , context ) : Promise < ListTagsForResourceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1ListTasksCommand = async ( output , context ) : Promise < ListTasksCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ListTasksCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , nextToken : undefined , tasks : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . nextToken !== undefined && data . nextToken !== null ) { contents . nextToken = __expectString ( data . nextToken ) ; } if ( data . tasks !== undefined && data . tasks !== null ) { contents . tasks = deserializeAws_restJson1TaskSummaryList ( data . tasks , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ListTasksCommandError = async ( output , context ) : Promise < ListTasksCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "AccessDeniedException" : case "com.amazonaws.snowdevicemanagement#AccessDeniedException" : response = { ... ( await deserializeAws_restJson1AccessDeniedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ThrottlingException" : case "com.amazonaws.snowdevicemanagement#ThrottlingException" : response = { ... ( await deserializeAws_restJson1ThrottlingExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1TagResourceCommand = async ( output , context ) : Promise < TagResourceCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1TagResourceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , } ; await collectBody ( output . body , context ) ; return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1TagResourceCommandError = async ( output , context ) : Promise < TagResourceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1UntagResourceCommand = async ( output , context ) : Promise < UntagResourceCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1UntagResourceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , } ; await collectBody ( output . body , context ) ; return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1UntagResourceCommandError = async ( output , context ) : Promise < UntagResourceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalServerException" : case "com.amazonaws.snowdevicemanagement#InternalServerException" : response = { ... ( await deserializeAws_restJson1InternalServerExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.snowdevicemanagement#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ValidationException" : case "com.amazonaws.snowdevicemanagement#ValidationException" : response = { ... ( await deserializeAws_restJson1ValidationExceptionResponse ( 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_restJson1AccessDeniedExceptionResponse = async ( parsedOutput , context ) : Promise < AccessDeniedException > => { const contents = { name : "AccessDeniedException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1InternalServerExceptionResponse = async ( parsedOutput , context ) : Promise < InternalServerException > => { const contents = { name : "InternalServerException" , $fault : "server" , $retryable : { } , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1ResourceNotFoundExceptionResponse = async ( parsedOutput , context ) : Promise < ResourceNotFoundException > => { const contents = { name : "ResourceNotFoundException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1ServiceQuotaExceededExceptionResponse = async ( parsedOutput , context ) : Promise < ServiceQuotaExceededException > => { const contents = { name : "ServiceQuotaExceededException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1ThrottlingExceptionResponse = async ( parsedOutput , context ) : Promise < ThrottlingException > => { const contents = { name : "ThrottlingException" , $fault : "client" , $retryable : { throttling : true , } , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1ValidationExceptionResponse = async ( parsedOutput , context ) : Promise < ValidationException > => { const contents = { name : "ValidationException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const serializeAws_restJson1Command = ( input , context ) : any => { return Command . visit ( input , { reboot : ( value ) => ( { reboot : serializeAws_restJson1Reboot ( value , context ) } ) , unlock : ( value ) => ( { unlock : serializeAws_restJson1Unlock ( value , context ) } ) , _ : ( name , value ) => ( { name : value } as any ) , } ) ; } ; const serializeAws_restJson1InstanceIdsList = ( input , context ) : any => { return input . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return entry ; } ) ; } ; const serializeAws_restJson1Reboot = ( input , context ) : any => { return { } ; } ; const serializeAws_restJson1TagMap = ( input , context ) : any => { return Object . entries ( input ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : value , } ; } , { } ) ; } ; const serializeAws_restJson1TargetList = ( input , context ) : any => { return input . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return entry ; } ) ; } ; const serializeAws_restJson1Unlock = ( input , context ) : any => { return { } ; } ; const deserializeAws_restJson1Capacity = ( output , context ) : Capacity => { return { available : __expectLong ( output . available ) , name : __expectString ( output . name ) , total : __expectLong ( output . total ) , unit : __expectString ( output . unit ) , used : __expectLong ( output . used ) , } as any ; } ; const deserializeAws_restJson1CapacityList = ( output , context ) : Capacity [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1Capacity ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1CpuOptions = ( output , context ) : CpuOptions => { return { coreCount : __expectInt32 ( output . coreCount ) , threadsPerCore : __expectInt32 ( output . threadsPerCore ) , } as any ; } ; const deserializeAws_restJson1DeviceSummary = ( output , context ) : DeviceSummary => { return { associatedWithJob : __expectString ( output . associatedWithJob ) , managedDeviceArn : __expectString ( output . managedDeviceArn ) , managedDeviceId : __expectString ( output . managedDeviceId ) , tags : output . tags !== undefined && output . tags !== null ? deserializeAws_restJson1TagMap ( output . tags , context ) : undefined , } as any ; } ; const deserializeAws_restJson1DeviceSummaryList = ( output , context ) : DeviceSummary [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1DeviceSummary ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1EbsInstanceBlockDevice = ( output , context ) : EbsInstanceBlockDevice => { return { attachTime : output . attachTime !== undefined && output . attachTime !== null ? __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( output . attachTime ) ) ) : undefined , deleteOnTermination : __expectBoolean ( output . deleteOnTermination ) , status : __expectString ( output . status ) , volumeId : __expectString ( output . volumeId ) , } as any ; } ; const deserializeAws_restJson1ExecutionSummary = ( output , context ) : ExecutionSummary => { return { executionId : __expectString ( output . executionId ) , managedDeviceId : __expectString ( output . managedDeviceId ) , state : __expectString ( output . state ) , taskId : __expectString ( output . taskId ) , } as any ; } ; const deserializeAws_restJson1ExecutionSummaryList = ( output , context ) : ExecutionSummary [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1ExecutionSummary ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1Instance = ( output , context ) : Instance => { return { amiLaunchIndex : __expectInt32 ( output . amiLaunchIndex ) , blockDeviceMappings : output . blockDeviceMappings !== undefined && output . blockDeviceMappings !== null ? deserializeAws_restJson1InstanceBlockDeviceMappingList ( output . blockDeviceMappings , context ) : undefined , cpuOptions : output . cpuOptions !== undefined && output . cpuOptions !== null ? deserializeAws_restJson1CpuOptions ( output . cpuOptions , context ) : undefined , createdAt : output . createdAt !== undefined && output . createdAt !== null ? __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( output . createdAt ) ) ) : undefined , imageId : __expectString ( output . imageId ) , instanceId : __expectString ( output . instanceId ) , instanceType : __expectString ( output . instanceType ) , privateIpAddress : __expectString ( output . privateIpAddress ) , publicIpAddress : __expectString ( output . publicIpAddress ) , rootDeviceName : __expectString ( output . rootDeviceName ) , securityGroups : output . securityGroups !== undefined && output . securityGroups !== null ? deserializeAws_restJson1SecurityGroupIdentifierList ( output . securityGroups , context ) : undefined , state : output . state !== undefined && output . state !== null ? deserializeAws_restJson1InstanceState ( output . state , context ) : undefined , updatedAt : output . updatedAt !== undefined && output . updatedAt !== null ? __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( output . updatedAt ) ) ) : undefined , } as any ; } ; const deserializeAws_restJson1InstanceBlockDeviceMapping = ( output , context ) : InstanceBlockDeviceMapping => { return { deviceName : __expectString ( output . deviceName ) , ebs : output . ebs !== undefined && output . ebs !== null ? deserializeAws_restJson1EbsInstanceBlockDevice ( output . ebs , context ) : undefined , } as any ; } ; const deserializeAws_restJson1InstanceBlockDeviceMappingList = ( output , context ) : InstanceBlockDeviceMapping [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1InstanceBlockDeviceMapping ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1InstanceState = ( output , context ) : InstanceState => { return { code : __expectInt32 ( output . code ) , name : __expectString ( output . name ) , } as any ; } ; const deserializeAws_restJson1InstanceSummary = ( output , context ) : InstanceSummary => { return { instance : output . instance !== undefined && output . instance !== null ? deserializeAws_restJson1Instance ( output . instance , context ) : undefined , lastUpdatedAt : output . lastUpdatedAt !== undefined && output . lastUpdatedAt !== null ? __expectNonNull ( __parseEpochTimestamp ( __expectNumber ( output . lastUpdatedAt ) ) ) : undefined , } as any ; } ; const deserializeAws_restJson1InstanceSummaryList = ( output , context ) : InstanceSummary [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1InstanceSummary ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1PhysicalNetworkInterface = ( output , context ) : PhysicalNetworkInterface => { return { defaultGateway : __expectString ( output . defaultGateway ) , ipAddress : __expectString ( output . ipAddress ) , ipAddressAssignment : __expectString ( output . ipAddressAssignment ) , macAddress : __expectString ( output . macAddress ) , netmask : __expectString ( output . netmask ) , physicalConnectorType : __expectString ( output . physicalConnectorType ) , physicalNetworkInterfaceId : __expectString ( output . physicalNetworkInterfaceId ) , } as any ; } ; const deserializeAws_restJson1PhysicalNetworkInterfaceList = ( output , context ) : PhysicalNetworkInterface [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1PhysicalNetworkInterface ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1ResourceSummary = ( output , context ) : ResourceSummary => { return { arn : __expectString ( output . arn ) , id : __expectString ( output . id ) , resourceType : __expectString ( output . resourceType ) , } as any ; } ; const deserializeAws_restJson1ResourceSummaryList = ( output , context ) : ResourceSummary [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1ResourceSummary ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1SecurityGroupIdentifier = ( output , context ) : SecurityGroupIdentifier => { return { groupId : __expectString ( output . groupId ) , groupName : __expectString ( output . groupName ) , } as any ; } ; const deserializeAws_restJson1SecurityGroupIdentifierList = ( output , context ) : SecurityGroupIdentifier [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1SecurityGroupIdentifier ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1SoftwareInformation = ( output , context ) : SoftwareInformation => { return { installState : __expectString ( output . installState ) , installedVersion : __expectString ( output . installedVersion ) , installingVersion : __expectString ( output . installingVersion ) , } as any ; } ; const deserializeAws_restJson1TagMap = ( output , context ) : { [ key ] : string ; } => { return Object . entries ( output ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : __expectString ( value ) as any , } ; } , { } ) ; } ; const deserializeAws_restJson1TargetList = ( output , context ) : string [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return __expectString ( entry ) as any ; } ) ; } ; const deserializeAws_restJson1TaskSummary = ( output , context ) : TaskSummary => { return { state : __expectString ( output . state ) , tags : output . tags !== undefined && output . tags !== null ? deserializeAws_restJson1TagMap ( output . tags , context ) : undefined , taskArn : __expectString ( output . taskArn ) , taskId : __expectString ( output . taskId ) , } as any ; } ; const deserializeAws_restJson1TaskSummaryList = ( output , context ) : TaskSummary [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1TaskSummary ( entry , context ) ; } ) ; } ; 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 isSerializableHeaderValue = ( value ) : boolean => value !== undefined && value !== null && value !== "" && ( ! Object . getOwnPropertyNames ( value ) . includes ( "length" ) || value . length != 0 ) && ( ! Object . getOwnPropertyNames ( value ) . includes ( "size" ) || value . size != 0 ) ; 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 "" ; } ;