<?php
require __DIR__ . '/../../vendor/autoload.php';
//date_default_timezone_set ("America/Mazatlan");


ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

function dumpAndDie($what){
  echo "<pre>";
  var_dump($what);
  die();
}

$settings = require __DIR__ . '/../../src/settings.php';

$settings = $settings['settings']['logger_omnibees'];
$logger = new Monolog\Logger($settings['name']);
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
$logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], $settings['level']));
 
$omnibees = new \APIS\Omnibees($logger);


$reservation = new \Modules\Reservation();
$room = new \Modules\Reservation\Room([], "2025-12-05", "2025-12-09");

$guest1 = new \Modules\Schemas\Guest([
  "first_name" => "Ob Adult 1",
  "last_name" => "Doe",
  "email" => "john.doe@example.com",
  "phone" => "123-456-7890",
  "PrimaryIndicator" => true,
  "AgeQualifyingCode" => "Adult",
  "ResGuestRPH" => 1,
]);
$room->addGuest($guest1);


$guest2 = new \Modules\Schemas\Guest([
  "first_name" => "Ob adult 2",
  "last_name" => "Doe",
  "email" => "john.doe@example.com",
  "phone" => "123-456-7890",
  "PrimaryIndicator" => false,
  "AgeQualifyingCode" => "Adult",
  "ResGuestRPH" => 2,
]);

$room->addGuest($guest2);

$room->setISOMarket("CHE");
$room->setResortId(198336);
$room->setRatePlan(3236772);

$data = $room->availableArray();

$response = $omnibees->GetHotelAvail($data,[$room]);

$ISOMarket = "AUS";
$rooms = [
  $room->reservationStartArray()
];

/*
a) DirectBill = 2
b) CreditCard = 5
c) Voucher = 3
d) PrePay = 4
*/


$response = $omnibees->SendHotelResInitiate($rooms, $ISOMarket,[$guest1, $guest2],false,[
  "PaymentType" => 3
]);

$response = $omnibees->SendHotelResCommit("RES000475-198336",'2ae4495a-0bf6-0ed1-a879-705349bb9fe4');
//  ------- termina la reserva original -----



//  ------- Inicia la seccion de cambios -----
$updated_room = new \Modules\Reservation\Room([], "2025-12-08", "2025-12-12");

$room->setISOMarket("CHE");
$room->setResortId(198336);
$room->setRatePlan(3236772);

$ReservationNumber = "RES000475-198336";
$IndexNumber = "RES000475-198336/1";
$data = $updated_room->availableArray();

//$response = $omnibees->GetHotelAvail($data,[$updated_room],true,$ReservationNumber,$IndexNumber);


$guest1 = new \Modules\Schemas\Guest([
  "first_name" => "Ob Adult 1 updated",
  "last_name" => "Doe",
  "email" => "john.doe@example.com",
  "phone" => "123-456-7890",
  "PrimaryIndicator" => true,
  "AgeQualifyingCode" => "Adult",
  "ResGuestRPH" => 1,
]);

$ISOMarket = "AUS";

$room = 
  [
    "StartDate" => "2025-12-08",
    "EndDate" => "2025-12-12",
    "HotelCode" => 198336,
    "RatePlanID" => 3236772,
    "RoomID" => 1036387,
    "Quantity" => 1,
    "ISOMarket" => $ISOMarket,
    "IndexNumber" => $IndexNumber,
    "GuestCounts" =>
      [
        $guest1->GuestCountsSchema("Adult",2,[1,2])
      ],
    "Guests" => [
      $guest1,
      $guest2
    ]
  ]
  ;

$transaction_id = "2ae4495a-0bf6-0ed1-a879-705349bb9fe4";
/*
$response = $omnibees->ChangeInitiate(
  $ReservationNumber,
  $transaction_id,
  $room
);
*/

//$response = $omnibees->ChangeDatesCommit($ReservationNumber,$transaction_id);

echo json_decode($response) ? json_encode(json_decode($response), JSON_PRETTY_PRINT) : $response;
