<?php
namespace App\Entity\System\Twilio;
use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableInterface;
use Cms\CoreBundle\Model\Interfaces\Loggable\LoggableInterface;
use Cms\TenantBundle\Entity\TenantedEntity;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Class TwilioCallerId
* @package App\Entity\System\Twilio
*
* @ORM\Entity(
* repositoryClass = "App\Doctrine\Repository\System\Twilio\TwilioCallerIdRepository",
* )
* @ORM\Table(
* name = "sys__twilio_caller_id",
* uniqueConstraints = {
* @ORM\UniqueConstraint(
* name = "uidx__tenant__phone_number",
* columns = {
* "tenant",
* "phoneNumber",
* },
* ),
* @ORM\UniqueConstraint(
* name = "uidx__tenant__name",
* columns = {
* "tenant",
* "name",
* },
* ),
* },
* )
*/
class TwilioCallerId extends TenantedEntity implements JsonSerializable, LoggableInterface
{
const STATUSES__SUCCESS = 'success';
const STATUSES__FAILED = 'failed';
/**
* @var TwilioConfig|null
*
* @ORM\ManyToOne(
* targetEntity = "App\Entity\System\Twilio\TwilioConfig",
* inversedBy = "callerIds",
* )
* @ORM\JoinColumn(
* name = "config",
* referencedColumnName = "id",
* nullable = false,
* onDelete = "CASCADE",
* )
*/
protected ?TwilioConfig $config = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = false,
* )
*
* @Groups("message_details")
*/
protected ?string $name = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = false,
* )
*/
protected ?string $phoneNumber = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $verificationExtension = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $verificationValidationCode = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $verificationCallSid = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $verificationStatus = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $twilioOutgoingCallerIdSid = null;
/**
* @return TwilioConfig|null
*/
public function getConfig(): ?TwilioConfig
{
return $this->config;
}
/**
* @param TwilioConfig $config
* @return $this
*/
public function setConfig(TwilioConfig $config): self
{
$this->config = $config;
return $this;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string|null
*/
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
/**
* @param string $phoneNumber
* @return $this
*/
public function setPhoneNumber(string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* @return string|null
*/
public function getVerificationExtension(): ?string
{
return $this->verificationExtension;
}
/**
* @param string|null $verificationExtension
* @return $this
*/
public function setVerificationExtension(?string $verificationExtension): self
{
$this->verificationExtension = $verificationExtension;
return $this;
}
/**
* @return string|null
*/
public function getVerificationValidationCode(): ?string
{
return $this->verificationValidationCode;
}
/**
* @param string|null $verificationValidationCode
* @return $this
*/
public function setVerificationValidationCode(?string $verificationValidationCode): self
{
$this->verificationValidationCode = $verificationValidationCode;
return $this;
}
/**
* @return string|null
*/
public function getVerificationCallSid(): ?string
{
return $this->verificationCallSid;
}
/**
* @param string|null $verificationCallSid
* @return $this
*/
public function setVerificationCallSid(?string $verificationCallSid): self
{
$this->verificationCallSid = $verificationCallSid;
return $this;
}
/**
* @return string|null
*/
public function getVerificationStatus(): ?string
{
return $this->verificationStatus;
}
/**
* @param string|null $verificationStatus
* @return $this
*/
public function setVerificationStatus(?string $verificationStatus): self
{
$this->verificationStatus = $verificationStatus;
return $this;
}
/**
* @return string|null
*/
public function getTwilioOutgoingCallerIdSid(): ?string
{
return $this->twilioOutgoingCallerIdSid;
}
/**
* @param string|null $twilioOutgoingCallerIdSid
* @return $this
*/
public function setTwilioOutgoingCallerIdSid(?string $twilioOutgoingCallerIdSid): self
{
$this->twilioOutgoingCallerIdSid = $twilioOutgoingCallerIdSid;
return $this;
}
/**
* @return bool
*/
public function isInitiated(): bool
{
return ( ! empty($this->getVerificationCallSid()));
}
/**
* @return bool
*/
public function isCompleted(): bool
{
return ( ! empty($this->getVerificationStatus()));
}
/**
* @return bool
*/
public function isSuccessful(): bool
{
return ($this->getVerificationStatus() === self::STATUSES__SUCCESS);
}
/**
* @return bool
*/
public function isFailed(): bool
{
return ($this->getVerificationStatus() === self::STATUSES__FAILED);
}
/**
* @return bool
*/
public function isVerified(): bool
{
return ( ! empty($this->getTwilioOutgoingCallerIdSid()));
}
/**
* {@inheritDoc}
*/
public function jsonSerialize(): array
{
static $refl = null;
$formatter = static function ($value, callable $formatter) {
switch (true) {
case is_scalar($value):
return $value;
case is_array($value):
$data = [];
foreach ($value as $k => $v) {
$data[$k] = $formatter($v, $formatter);
}
ksort($data);
return $data;
case $value instanceof UuidInterface:
return $value->__toString();
case $value instanceof IdentifiableInterface:
return $value->getId();
case $value instanceof \DateTimeInterface:
return $value->format(\DateTimeInterface::RFC3339);
case $value instanceof JsonSerializable:
return $value->jsonSerialize();
default:
return null;
}
};
if ( ! $refl) {
$refl = new \ReflectionObject($this);
}
$data = [];
foreach ($refl->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) {
$property->setAccessible(true);
$data[$property->getName()] = $formatter(
$property->getValue($this),
$formatter
);
$property->setAccessible(false);
}
ksort($data);
return $data;
}
/**
* {@inheritDoc}
*/
public function getLoggableDetails(): array
{
return [
'id' => (string) $this->getId(),
'title' => $this->getName(),
];
}
}