<?php
declare(strict_types=1);
namespace Slivki\BusinessFeature\Yclients\Dto;
use JsonSerializable;
use OpenApi\Annotations as OA;
use Nelmio\ApiDocBundle\Annotation\Model;
use Slivki\BusinessFeature\Yclients\HttpClient\Response\CompanyResponse;
use function array_map;
use function sprintf;
final class LocationDto implements JsonSerializable
{
/**
* @var array<PhoneNumberDto>
*
* @OA\Property(
* property="phoneNumbers",
* type="array",
* @OA\Items(
* ref=@Model(type=PhoneNumberDto::class)
* )
* ),
*/
private array $phoneNumbers;
/**
* @var string[]
*
* @OA\Property(
* property="geoLocation",
* type="array",
* @OA\Items(
* type="string",
* description="Широта и долгота в виде массива [широта, долгота]"
* ),
* )
*/
private array $geoLocation;
/**
* @var string
*
* @OA\Property(
* property="address",
* type="string",
* description="Адрес",
* example="г. Минск, ул. Ленина, д. 1"
* )
*/
private string $address;
/**
* @var string
*
* @OA\Property(
* property="workingHours",
* type="string",
* description="Часы работы",
* example="Пн-Пт: 9:00-18:00, Сб-Вс: выходной"
* )
*/
private string $workingHours;
/**
* @var string
*
* @OA\Property(
* property="description",
* type="string",
* description="Описание",
* example="Описание филиала"
* )
*/
private string $description;
public function __construct(
array $phoneNumbers,
array $geoLocation,
string $address,
string $workingHours,
string $description
) {
$this->phoneNumbers = $phoneNumbers;
$this->geoLocation = $geoLocation;
$this->address = $address;
$this->workingHours = $workingHours;
$this->description = $description;
}
public static function createFromCompany(CompanyResponse $companyResponse): LocationDto
{
return new self(
array_map(static fn (string $phone): PhoneNumberDto => new PhoneNumberDto(str_replace(['-', ' '], '', $phone), ''), $companyResponse->getPhones()),
[sprintf('%f,%f', $companyResponse->getCoordinateLat(), $companyResponse->getCoordinateLon())],
sprintf('%s, %s', $companyResponse->getCity(), $companyResponse->getAddress()),
$companyResponse->getSchedule(),
$companyResponse->getShortDescr(),
);
}
public function getPhoneNumbers(): array
{
return $this->phoneNumbers;
}
public function getGeoLocation(): array
{
return $this->geoLocation;
}
public function getAddress(): string
{
return $this->address;
}
public function getWorkingHours(): string
{
return $this->workingHours;
}
public function getDescription(): string
{
return $this->description;
}
public function jsonSerialize(): array
{
return [
'phoneNumbers' => $this->phoneNumbers,
'geoLocation' => $this->geoLocation,
'address' => $this->address,
'workingHours' => $this->workingHours,
'description' => $this->description,
];
}
}