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

async function getBrandedFares(requestData) {
  try {
    // Wrap under `data` key as required by Amadeus UPSelling API
    const requestBody = { data: requestData };

    // Call the Amadeus API
    const response = await amadeus.shopping.flightOffers.upselling.post(requestBody);

    return response.data;
  } catch (error) {
    // Log full error object for debugging
    console.error("Error fetching branded fares full error:", error);
    throw new Error("Unable to fetch branded fares. Please try again later.");
  }
}

module.exports = { getBrandedFares };
