Files
myep/src/BusProNet/Model/Room.php
T

108 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\BusProNet\Model;
use App\BusProNet\Constants;
use Symfony\Component\Serializer\Attribute\Context;
use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
/**
* Represents a room configuration with capacity, pricing, and availability information.
*
* This class handles room data including category, board options, capacity limits,
* pricing structure, and participant mapping. It provides serialization groups
* for different API contexts and booking management.
*/
class Room
{
public const SELECTION_TYPE_BY_PAX = 'by_pax';
public const SELECTION_TYPE_BY_ROOM = 'by_room';
/**
* Whether a room with this status and availability is offered for new bookings.
*
* Only 'Frei' rooms with rooms left. A room on request ('Anfrage') would turn the booking
* into an inquiry, so it is treated as sold out. Static and taking the raw values so the
* product export and the chatbot, which hold rooms as arrays, apply the same rule.
*/
public static function isBookableState(?string $status, ?int $available): bool
{
return Constants::STATUS_AVAILABLE === $status && ($available ?? 0) > 0;
}
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?int $id = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?string $category = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?int $boardId = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?string $code = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?string $label = null;
#[Groups(['booking'])]
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
public ?\DateTimeImmutable $dateFrom = null;
#[Groups(['booking'])]
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
public ?\DateTimeImmutable $dateTo = null;
#[Groups(['booking'])]
public ?int $totalCount = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?int $minPax = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?int $maxPax = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?int $nights = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?string $status = null;
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?int $available = null;
#[Groups(['booking'])]
public ?string $board = null;
/** @var list<int> */
#[Groups(['booking'])]
public array $mapping = [];
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?float $price = null;
#[Groups(['booking'])]
public ?float $totalPrice = null;
/** @var array<int, float|null> */
#[Groups(['booking'])]
public array $individualPrice = [];
/**
* Determines the selection type of the room based on its label.
*
* @return string Either self::SELECTION_TYPE_BY_PAX or self::SELECTION_TYPE_BY_ROOM
*/
public function getSelectionType(): string
{
if (1 === preg_match('/bett/i', $this->label)) {
return self::SELECTION_TYPE_BY_PAX;
}
return self::SELECTION_TYPE_BY_ROOM;
}
}