2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Shops;
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Actions\Shops\UpdateShopPickupExceptionsInput;
|
2026-10-01 11:25:05 +02:00
|
|
|
use App\Models\Shop;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Date;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
|
|
|
|
|
|
|
|
|
class UpdateShopPickupExceptionsRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly AppAdminAuthService $authService
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-01 11:25:05 +02:00
|
|
|
public function toUpdateShopPickupExceptionsInput(Shop $shop): UpdateShopPickupExceptionsInput
|
|
|
|
|
{
|
|
|
|
|
return new UpdateShopPickupExceptionsInput(
|
|
|
|
|
shop: $shop,
|
|
|
|
|
syncData: $this->toSyncData(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->authService->check();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'pickup-exceptions' => $this->input('pickup-exceptions', []),
|
|
|
|
|
'replacement_date' => $this->input('replacement_date', []),
|
|
|
|
|
'order_deadline_at' => $this->input('order_deadline_at', []),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 12:21:19 +02:00
|
|
|
/** @return array<string, mixed> */
|
2026-06-14 21:32:07 +02:00
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'pickup-exceptions' => ['array'],
|
2026-09-30 12:21:19 +02:00
|
|
|
'pickup-exceptions.*' => ['required', 'string', 'uuid', 'exists:pickup_exceptions,id'],
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
'replacement_date' => ['array'],
|
2026-09-30 12:31:38 +02:00
|
|
|
'replacement_date.*' => [
|
|
|
|
|
'nullable',
|
|
|
|
|
'date_format:Y-m-d',
|
|
|
|
|
'required_with:order_deadline_at.*',
|
|
|
|
|
],
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
'order_deadline_at' => ['array'],
|
2026-09-30 12:31:38 +02:00
|
|
|
'order_deadline_at.*' => [
|
|
|
|
|
'nullable',
|
|
|
|
|
'date_format:Y-m-d\TH:i',
|
|
|
|
|
'before:replacement_date.*',
|
|
|
|
|
],
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
'client_timezone' => ['required', 'timezone'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
protected function passedValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$deadlines = $this->array('order_deadline_at');
|
|
|
|
|
$timezone = $this->string('client_timezone')->value();
|
|
|
|
|
|
|
|
|
|
foreach ($deadlines as $id => $deadline) {
|
|
|
|
|
if (! empty($deadline)) {
|
|
|
|
|
$deadlines[$id] = Date::createFromFormat(
|
|
|
|
|
'Y-m-d\TH:i',
|
|
|
|
|
$deadline,
|
|
|
|
|
$timezone
|
|
|
|
|
)
|
|
|
|
|
?->setTimezone('UTC')
|
|
|
|
|
?->format('Y-m-d H:i:s');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->merge([
|
|
|
|
|
'order_deadline_at' => $deadlines,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'pickup-exceptions' => Str::lower(trans_choice('models.classes.pickup-exceptions', \INF)),
|
2026-09-30 12:21:19 +02:00
|
|
|
'pickup-exceptions.*' => Str::lower(trans_choice('models.classes.pickup-exceptions', 1)),
|
|
|
|
|
'replacement_date' => trans('validation.custom.attributes.replacement_date'),
|
2026-06-14 21:32:07 +02:00
|
|
|
'replacement_date.*' => trans('validation.custom.attributes.replacement_date'),
|
2026-09-30 12:21:19 +02:00
|
|
|
'order_deadline_at' => trans('validation.custom.attributes.order_deadline_at'),
|
2026-06-14 21:32:07 +02:00
|
|
|
'order_deadline_at.*' => trans('validation.custom.attributes.order_deadline_at'),
|
2026-09-30 12:21:19 +02:00
|
|
|
'client_timezone' => trans('validation.attributes.timezone'),
|
2026-06-14 21:32:07 +02:00
|
|
|
];
|
|
|
|
|
}
|
2026-09-30 12:21:19 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<string, array{replacement_date: string|null, order_deadline_at: string|null}>
|
|
|
|
|
*/
|
|
|
|
|
public function toSyncData(): array
|
|
|
|
|
{
|
|
|
|
|
$pickupExceptions = $this->array('pickup-exceptions');
|
|
|
|
|
$replacementDates = $this->array('replacement_date');
|
|
|
|
|
$orderDeadlines = $this->array('order_deadline_at');
|
|
|
|
|
|
|
|
|
|
$syncData = [];
|
|
|
|
|
|
|
|
|
|
foreach ($pickupExceptions as $exceptionId) {
|
|
|
|
|
$exceptionId = (string) $exceptionId;
|
|
|
|
|
$replacementDate = ! empty($replacementDates[$exceptionId]) ? (string) $replacementDates[$exceptionId] : null;
|
|
|
|
|
$orderDeadline = ! empty($orderDeadlines[$exceptionId]) ? (string) $orderDeadlines[$exceptionId] : null;
|
|
|
|
|
|
|
|
|
|
$syncData[$exceptionId] = [
|
|
|
|
|
'replacement_date' => $replacementDate,
|
|
|
|
|
'order_deadline_at' => $orderDeadline,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $syncData;
|
|
|
|
|
}
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|