// @flow
import assert from 'assert'
import { MAGNETIC_MODULE_TYPE } from '@opentrons/shared-data'
import * as errorCreators from '../../errorCreators'

import type {
  InvariantContext,
  RobotState,
  EngageMagnetArgs,
} from '../../types'

/** Engage magnet of specified magnetic module to given engage height. */
export const engageMagnet = (
  args: EngageMagnetArgs,
  invariantContext: InvariantContext,
  prevRobotState: RobotState
) => {
  const { module, engageHeight } = args
  const command = 'magneticModule/engageMagnet'

  if (module === null) {
    return { errors: [errorCreators.missingModuleError()] }
  }

  assert(
    invariantContext.moduleEntities[module]?.type === MAGNETIC_MODULE_TYPE,
    `expected module ${module} to be magdeck, got ${invariantContext.moduleEntities[module]?.type}`
  )

  return {
    commands: [
      {
        command: command,
        params: {
          module,
          engageHeight,
        },
      },
    ],
  }
}

@@ -163,44 +163,24 @@
 pe %7B
-%0A  InvariantContext,%0A  RobotState,%0A 
+ CommandCreator,
  Eng
@@ -192,18 +192,17 @@
 gnetArgs
-,%0A
+ 
 %7D from '
@@ -318,60 +318,58 @@
 gnet
- = (%0A  args: EngageMagnetArgs,%0A  invariantContext: I
+: CommandCreator%3CEngageMagnetArgs%3E = (%0A  args,%0A  i
 nvar
@@ -401,20 +401,8 @@
 tate
-: RobotState
 %0A) =

fix type annotation on engageMagnet (#5687)