const travelportService = require("../services/universalRecord.service");

// Debug: log what we imported
console.log("[Controller] travelportService:", travelportService);

exports.getPNRDetails = async (req, res) => {
  try {
    const { pnr } = req.params;
    console.log("[Controller] getPNRDetails called with PNR:", pnr);

    if (!pnr) {
      return res.status(400).json({
        success: false,
        message: "PNR is required"
      });
    }

    const response = await travelportService.retrievePNR(pnr);

    res.json({
      success: true,
      traceId: response.traceId,
      requestPNR: pnr,
      travelportResponse: response.json,
      rawSOAP: response.rawXML
    });

  } catch (error) {
    console.error("[Controller] Error in getPNRDetails:", error.message);
    res.status(500).json({
      success: false,
      message: error.message
    });
  }
};