<?php
declare(strict_types=1);
namespace Slivki\BusinessFeature\Yclients\Dto;
use OpenApi\Annotations as OA;
use JsonSerializable;
use Slivki\BusinessFeature\Yclients\HttpClient\Response\ServiceResponse;
final class ServiceDto implements JsonSerializable
{
/**
* @OA\Property(
* property="id",
* type="integer",
* description="Идентификатор услуги",
* ),
*
* @var int
*/
private int $id;
/**
* @OA\Property(
* property="title",
* type="string",
* description="Название услуги",
* ),
*
* @var string
*/
private string $title;
/**
* @OA\Property(
* property="category_id",
* type="integer",
* description="Идентификатор категории",
* ),
*
* @var int
*/
private int $categoryId;
/**
* @OA\Property(
* property="price_min",
* type="number",
* description="Минимальная цена",
* ),
*
* @var float
*/
private float $priceMin;
/**
* @OA\Property(
* property="price_max",
* type="number",
* description="Максимальная цена",
* ),
*
* @var float
*/
private float $priceMax;
/**
* @OA\Property(
* property="external_link",
* type="string",
* description="Ссылка на внешний ресурс",
* ),
*
* @var string|null
*/
private ?string $externalLink;
public function __construct(
int $id,
string $title,
int $categoryId,
float $priceMin,
float $priceMax,
?string $externalLink
) {
$this->id = $id;
$this->title = $title;
$this->categoryId = $categoryId;
$this->priceMin = $priceMin;
$this->priceMax = $priceMax;
$this->externalLink = $externalLink;
}
public static function createFromResponse(ServiceResponse $response, ?string $externalLink): self
{
return new self(
$response->getId(),
$response->getTitle(),
$response->getCategoryId(),
$response->getPriceMin(),
$response->getPriceMax(),
$externalLink
);
}
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'title' => $this->title,
'category_id' => $this->categoryId,
'price_min' => $this->priceMin,
'price_max' => $this->priceMax,
'external_link' => $this->externalLink,
];
}
}