const { getHotelsByCity, getHotelsByIds, getHotelsByGeoCode } = require('../models/hotelListModel');

exports.getHotelList = async (req, res) => {
  try {
    const { cityCode } = req.query;
    if (!cityCode) return res.status(400).json({ error: 'cityCode is required' });

    const hotels = await getHotelsByCity(cityCode);
    res.status(200).json({ success: true, count: hotels.length, data: hotels });
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: error.message });
  }
};

exports.getHotelsByIdsHandler = async (req, res) => {
  try {
    const { hotelIds } = req.query;
    if (!hotelIds) return res.status(400).json({ error: 'hotelIds parameter is required' });

    const hotels = await getHotelsByIds(hotelIds);
    res.status(200).json({ success: true, count: hotels.length, data: hotels });
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: error.message });
  }
};

exports.getHotelsByGeoCodeHandler = async (req, res) => {
  try {
    const { latitude, longitude, radius } = req.query;
    if (!latitude || !longitude) return res.status(400).json({ error: 'latitude and longitude are required' });

    const hotels = await getHotelsByGeoCode(latitude, longitude, radius || 5);
    res.status(200).json({ success: true, count: hotels.length, data: hotels });
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: error.message });
  }
};
