83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\BpnConnect;
|
|
|
|
use App\BpnConnect\Model\ContingentCalendarEntry;
|
|
use App\BpnConnect\Model\ContingentCalendarMeta;
|
|
use App\BpnConnect\Model\ContingentCalendarResponse;
|
|
use App\BpnConnect\Model\ContingentMode;
|
|
use App\BpnConnect\Model\ContingentRangeEntry;
|
|
use App\BpnConnect\Model\ContingentRangeResponse;
|
|
use App\BpnConnect\Model\ContingentStatus;
|
|
|
|
class ContingentsClient extends AbstractApiClient
|
|
{
|
|
private const string CALENDAR_PATH = '/api/v1/contingents/calendar';
|
|
|
|
public function getContingentCalendar(
|
|
string $hotelCode,
|
|
string $dateFrom,
|
|
string $dateTo,
|
|
): ContingentCalendarResponse {
|
|
$payload = $this->request(self::CALENDAR_PATH, [
|
|
'hotelCode' => $hotelCode,
|
|
'dateFrom' => $dateFrom,
|
|
'dateTo' => $dateTo,
|
|
'mode' => ContingentMode::Days->value,
|
|
]);
|
|
|
|
$entries = array_map(
|
|
static fn (array $item) => new ContingentCalendarEntry(
|
|
date: $item['date'],
|
|
status: ContingentStatus::from($item['status']),
|
|
),
|
|
$payload['data'] ?? [],
|
|
);
|
|
|
|
return new ContingentCalendarResponse($this->buildMeta($payload), $entries);
|
|
}
|
|
|
|
public function getContingentRanges(
|
|
string $hotelCode,
|
|
string $dateFrom,
|
|
string $dateTo,
|
|
): ContingentRangeResponse {
|
|
$payload = $this->request(self::CALENDAR_PATH, [
|
|
'hotelCode' => $hotelCode,
|
|
'dateFrom' => $dateFrom,
|
|
'dateTo' => $dateTo,
|
|
'mode' => ContingentMode::Ranges->value,
|
|
]);
|
|
|
|
$entries = array_map(
|
|
static fn (array $item) => new ContingentRangeEntry(
|
|
dateFrom: $item['date_from'],
|
|
dateTo: $item['date_to'],
|
|
status: ContingentStatus::from($item['status']),
|
|
),
|
|
$payload['data'] ?? [],
|
|
);
|
|
|
|
return new ContingentRangeResponse($this->buildMeta($payload), $entries);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $payload
|
|
*/
|
|
private function buildMeta(array $payload): ContingentCalendarMeta
|
|
{
|
|
$raw = $payload['meta'] ?? [];
|
|
|
|
return new ContingentCalendarMeta(
|
|
dateFrom: $raw['date_from'] ?? '',
|
|
dateTo: $raw['date_to'] ?? '',
|
|
mode: $raw['mode'] ?? '',
|
|
hotelCode: $raw['hotel_code'] ?? '',
|
|
hotelId: (int) ($raw['hotel_id'] ?? 0),
|
|
rowCount: (int) ($raw['row_count'] ?? 0),
|
|
);
|
|
}
|
|
}
|