const requests = {
  Produce: require('./produce'),
  Fetch: {},
  Offsets: {},
  Metadata: require('./metadata'),
  LeaderAndIsr: {},
  StopReplica: {},
  UpdateMetadata: {},
  ControlledShutdown: {},
  OffsetCommit: {},
  OffsetFetch: {},
  GroupCoordinator: {},
  JoinGroup: {},
  Heartbeat: {},
  LeaveGroup: {},
  SyncGroup: {},
  DescribeGroups: {},
  ListGroups: {},
  SaslHandshake: require('./saslhandshake'),
  ApiVersions: require('./apiVersions'),
  CreateTopics: {},
  DeleteTopics: {},
}

const lookup = versions => (apiKey, definition) => {
  const version = versions[apiKey]
  const bestImplementedVersion = Math.max.apply(this, definition.versions)
  const bestSupportedVersion = Math.min(bestImplementedVersion, version.maxVersion)
  return definition.protocol({ version: bestSupportedVersion })
}

module.exports = {
  requests,
  lookup,
}

const requests = {
  Produce: require('./produce'),
  Fetch: {},
  Offsets: {},
  Metadata: require('./metadata'),
  LeaderAndIsr: {},
  StopReplica: {},
  UpdateMetadata: {},
  ControlledShutdown: {},
  OffsetCommit: {},
  OffsetFetch: {},
  GroupCoordinator: {},
  JoinGroup: {},
  Heartbeat: {},
  LeaveGroup: {},
  SyncGroup: {},
  DescribeGroups: {},
  ListGroups: {},
  SaslHandshake: require('./saslHandshake'),
  ApiVersions: require('./apiVersions'),
  CreateTopics: {},
  DeleteTopics: {},
}

const lookup = versions => (apiKey, definition) => {
  const version = versions[apiKey]
  const bestImplementedVersion = Math.max.apply(this, definition.versions)
  const bestSupportedVersion = Math.min(bestImplementedVersion, version.maxVersion)
  return definition.protocol({ version: bestSupportedVersion })
}

module.exports = {
  requests,
  lookup,
}

Fix typo when loading the SASL Handshake protocol
Fix typo when loading the SASL Handshake protocol
