53 lines
1.1 KiB
PHP
53 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Booking;
|
|
|
|
use App\Entity\Booking;
|
|
use App\Entity\BookingSeries;
|
|
|
|
/**
|
|
* What creating a series actually achieved. A series is materialised best-effort: days that were
|
|
* already taken are skipped and reported, rather than failing the whole series.
|
|
*/
|
|
final readonly class SeriesResult
|
|
{
|
|
/**
|
|
* @param list<Booking> $created
|
|
* @param array<string, string> $skipped Y-m-d => reason
|
|
*/
|
|
public function __construct(
|
|
public BookingSeries $series,
|
|
public array $created,
|
|
public array $skipped,
|
|
) {
|
|
}
|
|
|
|
public function createdCount(): int
|
|
{
|
|
return \count($this->created);
|
|
}
|
|
|
|
public function skippedCount(): int
|
|
{
|
|
return \count($this->skipped);
|
|
}
|
|
|
|
public function isCompletelyBlocked(): bool
|
|
{
|
|
return [] === $this->created;
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public function skippedDates(): array
|
|
{
|
|
return array_map(
|
|
static fn (string $date): string => (new \DateTimeImmutable($date))->format('j.n.'),
|
|
array_keys($this->skipped),
|
|
);
|
|
}
|
|
}
|