<?php
namespace App\Entity;
use App\Repository\HistorySendRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\HistorySendRepository", repositoryClass=HistorySendRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class HistorySend
{
public const STATUSES = [
'Ошибка' => self::STATUS_ERROR,
'Успешно' => self::STATUS_SUCCESS,
];
public const STATUS_ERROR = 0;
public const STATUS_SUCCESS = 1;
public const STATUS_SENT_FROM_SERVICE = 2; // Успешно отправлено сервисом
public const CERTIFICATE_TYPE = 'certificate'; //Отправка сертификата получателю
public const CERT_REPORT_TYPE = 'cert_report'; //Отправка уведомления - Сертификат доставлен
public const ORDER_CREATE_TYPE = 'order_create'; //Отправка уведомления - Заказ оформлен
public const SEND_TYPE_SMS = 'sms';
public const SEND_TYPE_EMAIL = 'email';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $timestamp;
/**
* @ORM\Column(type="integer")
* @Assert\Choice(callback="getStatuses", message="Choose a valid status.")
*/
private $status;
/**
* @ORM\ManyToOne(targetEntity=Order::class, inversedBy="historySends")
* @ORM\JoinColumn(nullable=false)
*/
private $order;
/**
* @ORM\ManyToOne(targetEntity=WidgetUser::class, inversedBy="historySends", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $Client;
/**
* @ORM\Column(type="string", length=255)
*/
private $recipient;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $type;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $sendType;
/**
* @ORM\ManyToOne(targetEntity=OrderItem::class, inversedBy="historySends", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $orderItem;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $externalId;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $serviceStatus;
public function getId(): ?int
{
return $this->id;
}
public function getTimestamp(): ?DateTimeImmutable
{
return $this->timestamp;
}
public function setTimestamp(DateTimeImmutable $timestamp): self
{
$this->timestamp = $timestamp;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getStatusText(): ? string
{
return array_search($this->status, HistorySend::STATUSES)??self::STATUSES['Ошибка'];
}
public function getOrder(): ?Order
{
return $this->order;
}
public function setOrder(?Order $order): self
{
$this->order = $order;
return $this;
}
public function getClient(): ?WidgetUser
{
return $this->Client;
}
public function setClient(?WidgetUser $Client): self
{
$this->Client = $Client;
return $this;
}
public function getRecipient(): ?string
{
return $this->recipient;
}
public function setRecipient(string $recipient): self
{
$this->recipient = $recipient;
return $this;
}
/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string|null $type
* @return self
*/
public function setType(?string $type): self
{
if (in_array($type, [self::CERTIFICATE_TYPE, self::CERT_REPORT_TYPE, self::ORDER_CREATE_TYPE, null])) {
$this->type = $type;
}
return $this;
}
/**
* @return OrderItem|null
*/
public function getOrderItem(): ?OrderItem
{
return $this->orderItem;
}
/**
* @param OrderItem|null $orderItem
* @return HistorySend
*/
public function setOrderItem(?OrderItem $orderItem): self
{
$this->orderItem = $orderItem;
return $this;
}
/**
* @return string|null
*/
public function getExternalId(): string|null
{
return $this->externalId;
}
/**
* @param string|null $externalId
* @return HistorySend
*/
public function setExternalId(?string $externalId): self
{
$this->externalId = $externalId;
return $this;
}
/**
* @return string|null
*/
public function getServiceStatus(): string|null
{
return $this->serviceStatus;
}
/**
* @param string|null $serviceStatus
* @return HistorySend
*/
public function setServiceStatus(?string $serviceStatus): self
{
$this->serviceStatus = $serviceStatus;
return $this;
}
/**
* @return string|null
*/
public function getSendType(): ?string
{
return $this->sendType;
}
/**
* @param string|null $sendType
* @return HistorySend
*/
public function setSendType(?string $sendType): self
{
$this->sendType = $sendType;
return $this;
}
/**
* @return DateTimeImmutable|null
*/
public function getUpdatedAt(): ?DateTimeImmutable
{
return $this->updatedAt;
}
/**
* @param mixed $updatedAt
*/
public function setUpdatedAt(DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updateTimestamps(): void
{
$this->setUpdatedAt(new DateTimeImmutable());
}
}