<?php
namespace App\Entity\WhatsAppIntegration;
use App\Entity\Profile\JoboffererProfile;
use App\Entity\Profile\JobseekerProfile;
use App\Utility\DateTimeUtility;
use App\Utility\ReflectionHelper;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use InvalidArgumentException;
use JanusHercules\ApplicationAppointmentScheduling\Domain\Entity\ApplicationAppointmentScheduling;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="outgoing_whatsapp_messages"
* )
*/
class OutgoingWhatsAppMessage
{
public const MESSAGE_TYPE_NOTIFICATION_ABOUT_UNREAD_ORGANIC_CONVERSATION_MESSAGE = 0;
public const MESSAGE_TYPE_NOTIFICATION_ABOUT_UNREAD_INTEGRATED_EXTERNAL_PARTNER_CUSTOMER_PREMIUM_RADAR_MESSAGE = 1;
public const MESSAGE_TYPE_NOTIFICATION_ABOUT_GOOGLE_RATING_REQUEST = 2;
public const MESSAGE_TYPE_NOTIFICATION_ABOUT_APPLICATION_APPOINTMENT_SCHEDULING = 3;
/**
* @throws Exception
*/
public function __construct(
int $messageType,
string $receiverPhoneNumber,
?JobseekerProfile $receiverJobseekerProfile,
?JoboffererProfile $receiverJoboffererProfile,
string $messageBody,
?string $businessName = null,
?string $customerInternalId = null
) {
if (!ReflectionHelper::hasConstWithValue(
self::class,
'MESSAGE_TYPE_',
$messageType)
) {
throw new InvalidArgumentException("Value '$messageType' not allowed for messageType.");
}
$this->messageType = $messageType;
if (is_null($receiverJobseekerProfile)
&& is_null($receiverJoboffererProfile)
) {
throw new InvalidArgumentException('Jobofferer Profile and Jobseeker Profile cannot both be null.');
}
if (!is_null($receiverJobseekerProfile)
&& !is_null($receiverJoboffererProfile)
) {
throw new InvalidArgumentException('Jobofferer Profile and Jobseeker Profile cannot both be set.');
}
$this->jobseekerProfile = $receiverJobseekerProfile;
$this->joboffererProfile = $receiverJoboffererProfile;
$this->createdAt = DateTimeUtility::createDateTimeUtc();
$this->receiverPhoneNumber = mb_substr($receiverPhoneNumber, 0, 32);
$this->messageBody = mb_substr($messageBody, 0, 4096);
if (!is_null($businessName)) {
$this->businessName = mb_substr($businessName, 0, 128);
}
if (!is_null($customerInternalId)) {
$this->customerInternalId = mb_substr($customerInternalId, 0, 255);
}
}
/**
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
*
* @ORM\Column(name="id", type="guid")
*
* @ORM\Id
*/
private ?string $id;
public function getId(): ?string
{
return $this->id;
}
/**
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private DateTime $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @ORM\Column(name="sent_at", type="datetime", nullable=true)
*/
private DateTime $sentAt;
public function getSentAt(): DateTime
{
return $this->sentAt;
}
public function setSentAt(DateTime $sentAt): void
{
$this->sentAt = $sentAt;
}
/**
* @ORM\Column(type="smallint", name="message_type", nullable=false, options={"unsigned"=true})
*/
private int $messageType;
public function getMessageType(): int
{
return $this->messageType;
}
/**
* @ORM\Column(name="receiver_phone_number", type="text", length=32, nullable=false)
*/
private string $receiverPhoneNumber;
public function getReceiverPhoneNumber(): string
{
return $this->receiverPhoneNumber;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Profile\JobseekerProfile", inversedBy="conversationMessages", cascade={"persist"})
*
* @ORM\JoinColumn(name="jobseeker_profiles_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
private ?JobseekerProfile $jobseekerProfile;
public function getJobseekerProfile(): ?JobseekerProfile
{
return $this->jobseekerProfile;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Profile\JoboffererProfile", inversedBy="conversationMessages", cascade={"persist"})
*
* @ORM\JoinColumn(name="jobofferer_profiles_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
private ?JoboffererProfile $joboffererProfile;
public function getJoboffererProfile(): ?JoboffererProfile
{
return $this->joboffererProfile;
}
/**
* @ORM\Column(name="message_body", type="text", length=4096, nullable=false)
*/
private string $messageBody;
public function getMessageBody(): string
{
return $this->messageBody;
}
/**
* @ORM\Column(name="business_name", type="text", length=128, nullable=true)
*/
private ?string $businessName = null;
public function getBusinessName(): ?string
{
return $this->businessName;
}
/**
* @ORM\Column(name="integrated_external_partner_customers_internal_id", type="text", length=255, nullable=true)
*/
private ?string $customerInternalId = null;
public function getCustomerInternalId(): ?string
{
return $this->customerInternalId;
}
/**
* @ORM\OneToOne(
* targetEntity="JanusHercules\ApplicationAppointmentScheduling\Domain\Entity\ApplicationAppointmentScheduling",
* mappedBy="outgoingWhatsAppMessage"
* )
*/
private ?ApplicationAppointmentScheduling $applicationAppointmentScheduling = null;
public function getApplicationAppointmentScheduling(): ?ApplicationAppointmentScheduling
{
return $this->applicationAppointmentScheduling;
}
}