const express = require("express");
const router = express.Router();
const DeviceSetController = require("../controller/device.set.controller");

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

// Device Log Save route
router.get(
  "/:operating_type/:token/:device_id/:remote_name/:remote_type",
  async (req, res) => {
    try {
      const { token, device_id, remote_name, remote_type, operating_type } =
        req.params;

        console.log(req.params);

      // Token Control Middleware
      const result = await DeviceSetController.set(
        token,
        device_id,
        remote_name,
        remote_type,
        operating_type
      );

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

module.exports = router;
