*/ final readonly class GetShopQuery implements Query { public function __construct( private ShopRepository $shopRepository, private PickupExceptionRepository $pickupExceptionRepository, ) { } /** * @param \App\Queries\Shops\GetShopQueryInput $input */ #[\Override] public function __invoke(QueryInput $input): ShopDto { Assert::isInstanceOf($input, GetShopQueryInput::class); $domainShop = $this->shopRepository->getDefaultShop(); $pickupExceptionList = $this->pickupExceptionRepository->getExceptionsAssociatedWithShop($domainShop->id); $mappedExceptions = Collection::make( array_map( fn (ShopPickupOverride $pickupOverride): PickupExceptionDto => $this->mapDomainPickupExceptionToDto( $pickupOverride, ), $pickupExceptionList ) ); return $this->mapDomainShopToDto( $domainShop, $mappedExceptions ); } /** @param \Illuminate\Support\Collection $pickupExceptionList */ private function mapDomainShopToDto( Shop $domainShop, Collection $pickupExceptionList, ): ShopDto { return new ShopDto( id: $domainShop->id->value->toString(), name: $domainShop->name, address: $domainShop->address, postcode: $domainShop->postcode, city: $domainShop->city, phone: $domainShop->phone, latitude: $domainShop->latitude, longitude: $domainShop->longitude, default: $domainShop->isDefault, pickupExceptions: $pickupExceptionList, ); } private function mapDomainPickupExceptionToDto(ShopPickupOverride $shopPickupOverride): PickupExceptionDto { $exception = $shopPickupOverride->exception; return new PickupExceptionDto( id: $exception->id->value->toString(), date: $exception->date, label: $exception->label, repeatable: $exception->repeatable, repeat_frequency: $exception->repeatFrequency, auto_updated: $exception->autoUpdated, pivot: $this->mapShopPickupExceptionPivotDto( $shopPickupOverride->replacementDate, $shopPickupOverride->orderDeadlineAt, ), ); } private function mapShopPickupExceptionPivotDto( ?CarbonInterface $replacementDate, ?CarbonInterface $orderDeadlineAt, ): ShopPickupExceptionPivotDto { return new ShopPickupExceptionPivotDto( $replacementDate, $orderDeadlineAt ); } }