authService->getCustomerAsMandatory(); return new ApplyPickTimeSlotInput( shopperId: $customer->getId(), timeslot: $this->getTimeslot(), ); } public function authorize(): bool { return $this->authService->check(); } #[\Override] protected function prepareForValidation(): void { $this->merge([ 'basketTotal' => $this->basketService ->getBasket() ->totalTaxIncluded() ->getAmount(), ]); } public function getTimeslot(): CarbonInterface { return CarbonImmutable::createFromFormat( 'Y-m-d', $this->string('timeslot')->value() )?->startOfDay() ?? throw new \InvalidArgumentException('Invalid timeslot format'); } /** @return array */ public function rules(): array { return [ 'timeslot' => ['required', 'string', 'date_format:Y-m-d'], 'basketTotal' => [ function (string $_, mixed $__, \Closure $fail) { try { $customer = $this->authService->getCustomerAsMandatory(); $shopper = $this->shopperRepository->getByIdOrFail($customer->getId()); $atDate = $this->getTimeslot(); $basket = $this->basketService->getBasket(); $this->orderTunnelService->assertBasketWeeklyAmountWithinLimitFor( shopper: $shopper, withBasket: $basket, atDate: $atDate ); } catch (WeeklyLimitExceededException) { $fail(trans('You will reach the maximum weekly order limit with this basket.')); } }, ], ]; } /** @return array */ #[\Override] public function attributes(): array { return [ 'timeslot' => trans('validation.custom.attributes.timeslot'), ]; } }