const amadeus = require('../config/amadeusClient');

exports.getHotelRatings = async (req, res) => {
  try {
    const { hotelIds } = req.query;

    if (!hotelIds) {
      return res.status(400).json({
        errors: [
          {
            status: 400,
            title: 'Missing required parameter',
            detail: 'hotelIds parameter is required'
          }
        ]
      });
    }

    //  Call Amadeus API
    const response = await amadeus.eReputation.hotelSentiments.get({ hotelIds });

    // Return EXACT raw Amadeus API response
    if (response && response.result) {
      return res.status(200).json(response.result);
    }

    // No data case
    return res.status(404).json({
      errors: [
        {
          status: 404,
          title: 'No ratings found',
          detail: `No ratings found for hotelIds: ${hotelIds}`
        }
      ]
    });
  } catch (error) {
    console.error('Hotel Ratings Controller Error:', error);
    return res.status(500).json({
      errors: [
        {
          status: 500,
          title: 'Internal Server Error',
          detail: error.description || error.message
        }
      ]
    });
  }
};
