<?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);

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

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

$guest3 = new \Modules\Schemas\Guest([
  "first_name" => "Child one",
  "last_name" => "Doe",
  "email" => "john.doe@example.com",
  "phone" => "123-456-7890",
  "PrimaryIndicator" => false,
  "AgeQualifyingCode" => "Child",
  "Age"=> 1,
  "ResGuestRPH" => 3,
]);


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

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

$guest6 = new \Modules\Schemas\Guest([
  "first_name" => "Child three",
  "last_name" => "Doe",
  "email" => "john.doe@example.com",
  "phone" => "123-456-7890",
  "PrimaryIndicator" => false,
  "AgeQualifyingCode" => "Child",
  "Age"=> 10,
  "ResGuestRPH" => 3,
]);
$room = new \Modules\Schemas\RoomStayCandidates([$guest1,$guest2,$guest3]);
$room2 = new \Modules\Schemas\RoomStayCandidates([$guest4,$guest5,$guest6]);

// no refund rateID 3236379
// refund rateID 3236377

$data = [
  "cin" => "2025-10-09",
  "cout" => "2025-10-11",
  "hotel_code" => 198336,
  "rate_plan" => [ 3236379 , 3236377 ],
  "room_id" => "",
  "ISOMarket" => "ALL"
];

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

$ISOMarket = "PRT";
$rooms = [
  [
    "StartDate" => "2025-10-09",
    "EndDate" => "2025-10-11",
    "HotelCode" => 198336,
    "RatePlanID" => 3236379,
    "RoomID" => 1036385,
    "Quantity" => 1,
    "GuestCounts" =>
      [
        $guest1->GuestCountsSchema("Adult",2,[1,2]),
        $guest1->GuestCountsSchema("Child",1,[3],1)
      ]
      ],
      [
    "StartDate" => "2025-10-09",
    "EndDate" => "2025-10-11",
    "HotelCode" => 198336,
    "RatePlanID" => 3236377,
    "RoomID" => 1036385,
    "Quantity" => 1,
    "GuestCounts" =>
      [
        $guest1->GuestCountsSchema("Adult",2,[4,5]),
        $guest1->GuestCountsSchema("Child",1,[6],10)
      ]
  ]
];
$response = $omnibees->SendHotelResInitiate($rooms, $ISOMarket,[$guest1, $guest2, $guest3,$guest4,$guest5,$guest6]);
//$response = $omnibees->SendHotelResCommit("RES000461-198336",'316e8507-902d-99ea-1818-ecf0c2847f43');

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