const express = require("express");
const router = express.Router();
const SaveController = require("../controller/save.controller");

router.use(express.urlencoded({ extended: false }));
router.use(express.json())

// Save route
router.post("/", async (req, res) => {

  try {
    // Token Control Middleware
    const result = await SaveController.save(
      req.body.token,
      req.body.device_name,
      req.body.device_type,
      req.body.manifactor,
      req.body.serial_number,
      req.body.model,
      req.body.firmware_version,
      req.body.device_ip_address,
      req.body.sensor_value,
      req.body.battery_life,
    );

    return res.status(200).json({
      error: false,
      result
    });
  } catch (error) {
    res.status(400).json({
      error: true,
      result: error.message
    });
  }
});

module.exports = router;
