45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Shops;
|
|
|
|
use App\Contracts\ActionInput;
|
|
use App\Models\Shop;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
final readonly class UpdateShopPickupExceptionsInput implements ActionInput
|
|
{
|
|
/**
|
|
* @param array<array-key, array{replacement_date: string|null, order_deadline_at: string|null}> $syncData
|
|
*/
|
|
public function __construct(
|
|
public Shop $shop,
|
|
public array $syncData,
|
|
) {
|
|
foreach ($this->syncData as $item) {
|
|
Assert::isArray($item, 'Each sync item must be an array.');
|
|
Assert::keyExists($item, 'replacement_date', 'Sync item must contain replacement_date key.');
|
|
Assert::keyExists($item, 'order_deadline_at', 'Sync item must contain order_deadline_at key.');
|
|
Assert::nullOrString($item['replacement_date'], 'replacement_date must be a string or null.');
|
|
Assert::nullOrString($item['order_deadline_at'], 'order_deadline_at must be a string or null.');
|
|
|
|
if ($item['order_deadline_at'] !== null) {
|
|
Assert::notNull(
|
|
$item['replacement_date'],
|
|
'A replacement date is required when an order deadline is set.'
|
|
);
|
|
}
|
|
|
|
if ($item['replacement_date'] !== null && $item['order_deadline_at'] !== null) {
|
|
$replacementDate = new \DateTimeImmutable($item['replacement_date']);
|
|
$orderDeadlineAt = new \DateTimeImmutable($item['order_deadline_at']);
|
|
|
|
Assert::true(
|
|
$orderDeadlineAt < $replacementDate,
|
|
'Order deadline must be strictly before the replacement date.'
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|