const express = require("express");
const router = express.Router();

const regionService = require("../services/regionService");
const logger = require("../utils/logger");

router.get("/read/id/:idRegion", async (req, res) => {
  const idRegion = req.params.idRegion;

  try {
    const region = await regionService.getRegionById(idRegion);

    res.json({ valid: Boolean(region), region });
  } catch (error) {
    logger.log("error", `Error fetching region with ID ${idRegion}:`, error);

    res.status(500).json({ valid: false, error: "Internal Server Error" });
  }
});

module.exports = router;
