const hotelService = require("../services/hotelAutoCompleteService");

const hotelAutoComplete = async (req, res) => {

  try {

    const keyword = req.query.name?.trim();

    console.log("Search keyword:", keyword);

    if (!keyword || keyword.length < 3) {
      return res.status(400).json({
        success: false,
        message: "Minimum 3 characters required"
      });
    }

    const locations = await hotelService.searchHotelLocations(keyword);

    res.status(200).json({
      success: true,
      totalResults: locations.length,
      data: locations
    });

  } catch (error) {

    console.error("Hotel AutoComplete Error:", error);

    res.status(500).json({
      success: false,
      message: "Internal server error"
    });

  }

};

module.exports = hotelAutoComplete;