const hotelCancelService = require("../services/hotelCancelService");

exports.hotelCancel = async (req, res) => {
  console.log("==================================================");
  console.log("CONTROLLER: HotelCancelReq - START");
  console.log("==================================================");

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

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

    // Basic Validation
    if (
      !traceId ||
      !targetBranch ||
      !authorizedBy ||
      !providerCode ||
      !providerLocatorCode ||
      version === undefined
    ) {
      console.log("Validation Failed - Missing required fields");

      return res.status(400).json({
        success: false,
        message: "Missing required fields"
      });
    }

    const result = await hotelCancelService.hotelCancel({
      traceId,
      targetBranch,
      authorizedBy,
      providerCode,
      providerLocatorCode,
      version
    });

    console.log("CONTROLLER: HotelCancelReq - SUCCESS");

    return res.status(200).json({
      success: true,
      message: "Hotel cancel processed successfully",
      data: result
    });

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

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