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

async function getPriceAnalysis({ originIataCode, destinationIataCode, departureDate, currencyCode = 'INR', oneWay = true }) {
  try {
    const response = await amadeus.analytics.itineraryPriceMetrics.get({
      originIataCode,
      destinationIataCode,
      departureDate,
      currencyCode,
      oneWay,
    });

    return response.data;
  } catch (error) {
    console.error("Error fetching price analysis:", error.response?.data || error.message);
    throw new Error(error.response?.data?.errors?.[0]?.detail || "Unable to fetch price analysis.");
  }
}

module.exports = { getPriceAnalysis };
