const services = require('../services')

const { firmware } = services

const postLookFirmware = async (req, res, next) => {
  const { serialNumber, hash, version, type, hardwareIndex, hardwareVersion } = req.body
  try {
    const obj = await firmware.lookFirmware(serialNumber, hash, version, type, hardwareIndex, hardwareVersion)
    res.send(obj)
  } catch (e) {
    console.log(e.message)
    res.sendStatus(500)
  }
}

const postSyncFirmware = async (req, res, next) => {
  const { serialNumber, hash, version, type, hardwareIndex, hardwareVersion } = req.body
  try {
    const obj = await firmware.syncFirmware(serialNumber, hash, version, type, hardwareIndex, hardwareVersion)
    res.send(obj)
  } catch (e) {
    console.log(e.message)
    res.sendStatus(500)
  }
}

module.exports = {
  postLookFirmware,
  postSyncFirmware
}