<?php
declare(strict_types=1);
namespace Slivki\Factory\Dto\WorkExample;
use Slivki\Dto\WorkExample\WorkExampleAddressWithDistanceDto;
use Slivki\Dto\WorkExample\WorkExampleWithAddressesDto;
use Slivki\Entity\GeoLocation;
use Slivki\Entity\WorkExample;
use Slivki\Response\Beauty\Offer\Factory\MasterResponseFactory;
use Slivki\Services\Seo\SeoResourceService;
use Slivki\ValueObject\Coordinate;
use Symfony\Component\HttpFoundation\UrlHelper;
use function array_map;
final class WorkExampleWithAddressesDtoFactory
{
private SeoResourceService $seoResourceService;
private UrlHelper $urlHelper;
private WorkExampleAddressWithDistanceDtoFactory $workExampleAddressWithDistanceDtoFactory;
private MasterResponseFactory $masterResponseFactory;
public function __construct(
SeoResourceService $seoResourceService,
UrlHelper $urlHelper,
WorkExampleAddressWithDistanceDtoFactory $workExampleAddressWithDistanceDtoFactory,
MasterResponseFactory $masterResponseFactory
) {
$this->seoResourceService = $seoResourceService;
$this->urlHelper = $urlHelper;
$this->workExampleAddressWithDistanceDtoFactory = $workExampleAddressWithDistanceDtoFactory;
$this->masterResponseFactory = $masterResponseFactory;
}
public function create(WorkExample $workExample, ?Coordinate $currentUserPosition): WorkExampleWithAddressesDto
{
$offerId = $workExample->getOffer()->getID();
return new WorkExampleWithAddressesDto(
$workExample->getId(),
$offerId,
$this->seoResourceService->getOfferUrlWithDomain($offerId),
array_map(
fn (GeoLocation $geoLocation): WorkExampleAddressWithDistanceDto =>
$this->workExampleAddressWithDistanceDtoFactory->create($geoLocation, $currentUserPosition),
$workExample->getGeoLocations()->toArray(),
),
null !== $workExample->getBeautyMaster()
? $this->masterResponseFactory->create($workExample->getBeautyMaster())
: null,
null === $workExample->getImageUrl() ? null : $this->urlHelper->getAbsoluteUrl($workExample->getImageUrl()),
$workExample->getDescription(),
$workExample->getPrice(),
);
}
}