const universalRecordModifyService = require("../services/URhotelModifyService");

exports.modifyUniversalRecordHotel = async (req, res) => {
  console.log("=======================================================");
  console.log("CONTROLLER: UniversalRecordModifyReq (HotelAdd) - START");
  console.log("=======================================================");

  try {
    console.log("Incoming Request Body:");
    console.log(JSON.stringify(req.body, null, 2));

    const {
      traceId,
      targetBranch,
      authorizedBy,
      providerCode,
      providerLocatorCode,
      universalLocatorCode,
      hotelReservationLocator
    } = req.body;

    // Required field validation
    if (
      !traceId ||
      !targetBranch ||
      !authorizedBy ||
      !providerCode ||
      !providerLocatorCode ||
      !universalLocatorCode ||
      !hotelReservationLocator
    ) {
      console.error("❌ Missing required fields in request");
      return res.status(400).json({
        success: false,
        message: "Missing required request fields"
      });
    }

    console.log("Calling Service Layer...");

    const result = await universalRecordModifyService.modifyUniversalRecordHotel({
      traceId,
      targetBranch,
      authorizedBy,
      providerCode,
      providerLocatorCode,
      universalLocatorCode,
      hotelReservationLocator
    });

    console.log("CONTROLLER: UniversalRecordModifyReq - SUCCESS");
    console.log("=======================================================");

    return res.status(200).json({
      success: true,
      data: result
    });

  } catch (error) {
    console.error("❌ CONTROLLER ERROR:");
    console.error(error.message);

    return res.status(500).json({
      success: false,
      message: error.message
    });
  }
};