<?php
declare(strict_types=1);
namespace Slivki\Dto\OnlineOrder;
use DateTimeImmutable;
use JsonSerializable;
use OpenApi\Annotations as OA;
use Nelmio\ApiDocBundle\Annotation\Model;
use Slivki\Enum\DeviceTypeEnum;
use Slivki\Enum\Order\DeliveryType;
use Slivki\Enum\Order\PaymentType;
use Slivki\Enum\Order\OrderPartnerStatus;
final class OnlineOrderDto implements JsonSerializable
{
private BuyerDto $buyer;
/**
* @OA\Property(
* property="paidAt",
* type="string",
* format="date-time",
* description="Дата покупки",
* example="2023-02-18 10:30:23",
* )
*/
private DateTimeImmutable $paidAt;
/**
* @OA\Property(
* property="paymentType",
* type="string",
* description="Тип оплаты",
* enum={"Online","Наличные","Терминал","SlivkiPay"},
* )
*/
private PaymentType $paymentType;
/**
* @OA\Property(
* property="deviceType",
* type="string",
* description="Тип оплаты",
* enum={"Сайт","Мобильная версия сайта","Приложение"},
* )
*/
private DeviceTypeEnum $deviceType;
/**
* @OA\Property(
* property="deliveryType",
* type="string",
* description="Тип оплаты",
* enum={"Доставка","Самовывоз"},
* )
*/
private DeliveryType $deliveryType;
/**
* @OA\Property(
* type="array",
* description="Адреса с расстояниями до них",
* @OA\Items(ref=@Model(type=OrderItemDto::class)),
* )
*
* @var array<OrderItemDto>
*/
private array $composition;
/**
* @OA\Property(
* type="array",
* description="Промокоды",
* @OA\Items(type="string"),
* )
*
* @var array<string>
*/
private array $codes;
/**
* @OA\Property(
* property="amount",
* type="number",
* format="float",
* description="Сумма (BYN)",
* example="100.50",
* )
*/
private float $amount;
/**
* @OA\Property(
* property="orderId",
* description="Id заказа",
* example="123456",
* )
*/
private int $orderId;
/**
* @OA\Property(
* property="comment",
* description="Адрес",
* example="Не входить убьет!",
* nullable=true,
* )
*/
private ?string $comment;
/**
* @OA\Property(
* property="preOrderAt",
* type="string",
* format="date-time",
* description="Предзаказ на время",
* example="2023-02-18 10:30:23",
* nullable=true,
* )
*/
private ?DateTimeImmutable $preOrderAt;
/**
* @OA\Property(
* property="deliveryPrice",
* type="number",
* format="float",
* description="Стоимость доставки (BYN)",
* example="5.50",
* nullable=true,
* )
*/
private ?float $deliveryPrice;
/**
* @OA\Property(
* property="address",
* description="Адрес",
* example="Минск, ул. Янки Купалы, 25",
* nullable=true,
* )
*/
private ?string $address;
/**
* @OA\Property(
* property="partnerStatus",
* nullable=true,
* type="string",
* enum=OrderPartnerStatus::LABELS,
* example="Новый",
* description="Статус заказа установленный партнером (Новый, Принят, Выполнен, Отменен)",
* )
*/
private ?string $partnerStatus;
public function __construct(
BuyerDto $buyer,
DateTimeImmutable $paidAt,
PaymentType $paymentType,
DeviceTypeEnum $deviceType,
DeliveryType $deliveryType,
array $composition,
array $codes,
float $amount,
int $orderId,
?string $comment,
?DateTimeImmutable $preOrderAt,
?float $deliveryPrice,
?string $address,
?string $partnerStatus
) {
$this->buyer = $buyer;
$this->paidAt = $paidAt;
$this->paymentType = $paymentType;
$this->deviceType = $deviceType;
$this->deliveryType = $deliveryType;
$this->composition = $composition;
$this->codes = $codes;
$this->amount = $amount;
$this->orderId = $orderId;
$this->comment = $comment;
$this->preOrderAt = $preOrderAt;
$this->deliveryPrice = $deliveryPrice;
$this->address = $address;
$this->partnerStatus = $partnerStatus;
}
public function getBuyer(): BuyerDto
{
return $this->buyer;
}
public function getPaidAt(): DateTimeImmutable
{
return $this->paidAt;
}
public function getPaymentType(): PaymentType
{
return $this->paymentType;
}
public function getDeviceType(): DeviceTypeEnum
{
return $this->deviceType;
}
public function getDeliveryType(): DeliveryType
{
return $this->deliveryType;
}
public function getComposition(): array
{
return $this->composition;
}
public function getCodes(): array
{
return $this->codes;
}
public function getAmount(): float
{
return $this->amount;
}
public function getOrderId(): int
{
return $this->orderId;
}
public function getComment(): ?string
{
return $this->comment;
}
public function getPreOrderAt(): ?DateTimeImmutable
{
return $this->preOrderAt;
}
public function getDeliveryPrice(): ?float
{
return $this->deliveryPrice;
}
public function getAddress(): ?string
{
return $this->address;
}
public function getPartnerStatus(): ?string
{
return $this->partnerStatus;
}
public function jsonSerialize(): array
{
return [
'buyer' => $this->buyer,
'paidAt' => $this->paidAt->format('Y-m-d H:i:s'),
'paymentType' => PaymentType::names()[$this->paymentType->getValue()],
'deviceType' => DeviceTypeEnum::names()[$this->deviceType->getValue()],
'deliveryType' => DeliveryType::names()[$this->deliveryType->getValue()],
'composition' => $this->composition,
'codes' => $this->codes,
'amount' => $this->amount,
'orderId' => $this->orderId,
'preOrderAt' => null === $this->preOrderAt ? null : $this->preOrderAt->format('Y-m-d H:i:s'),
'deliveryPrice' => $this->deliveryPrice,
'address' => $this->address,
'partnerStatus' => $this->partnerStatus,
];
}
}