<?php
declare(strict_types=1);
namespace JanusHercules\IndeedCampaignManagement\Domain\Entity;
use App\Utility\DatabaseIdGenerator;
use App\Utility\DateTimeUtility;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use JanusHercules\IndeedCampaignManagement\Domain\Enum\CampaignType;
use ValueError;
#[ORM\Entity]
#[ORM\Table(name: 'icm_campaign_definitions')]
class CampaignDefinition
{
/**
* @throws Exception
*/
public function __construct(
string $name,
DateTime $validFrom,
DateTime $validUntil,
int $poolSize,
CampaignType $campaignType,
?string $forRecurrentJobId = null,
?string $forCustomerInternalId = null,
) {
$this->poolSize = $poolSize;
$this->campaignType = $campaignType;
$this->name = $name;
$this->createdAt = DateTimeUtility::createDateTimeUtc();
$this->validFrom = $validFrom;
$this->validUntil = $validUntil;
$this->forRecurrentJobId = $forRecurrentJobId;
$this->forCustomerInternalId = $forCustomerInternalId;
if (($campaignType === CampaignType::SELF_SERVICE_TRAFFIC_CAMPAIGN || $campaignType->isFlexMembershipType()) && is_null($forRecurrentJobId)) {
throw new ValueError('For flex higher-priced membership and self-service traffic campaigns, a recurrent job id must be provided.');
}
if ($campaignType === CampaignType::CUSTOMER && is_null($forCustomerInternalId)) {
throw new ValueError('For customer campaigns, a customer internal id must be provided.');
}
if (($campaignType === CampaignType::SELF_SERVICE_TRAFFIC_CAMPAIGN || $campaignType->isFlexMembershipType()) && !is_null($forCustomerInternalId)) {
throw new ValueError('For flex higher-priced membership and self-service traffic campaigns, a customer internal id must not be provided.');
}
if ($campaignType === CampaignType::CUSTOMER && !is_null($forRecurrentJobId)) {
throw new ValueError('For customer campaigns, a recurrent job id must not be provided.');
}
if (!$campaignType->isFlexMembershipType() && $campaignType !== CampaignType::SELF_SERVICE_TRAFFIC_CAMPAIGN && $campaignType !== CampaignType::CUSTOMER && (!is_null($forRecurrentJobId) || !is_null($forCustomerInternalId))) {
throw new ValueError('For non-flex-higher-priced-membership and non-self-service traffic campaigns and non-customer campaigns, neither recurrent job id nor customer internal id must be provided.');
}
if (($campaignType === CampaignType::SELF_SERVICE_TRAFFIC_CAMPAIGN || $campaignType->isFlexMembershipType()) && $poolSize !== 1) {
throw new ValueError('For self-service traffic campaigns, the pool size must be 1.');
}
}
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
#[ORM\Column(
type : Types::GUID,
unique: true
)]
private ?string $id = null;
public function getId(): ?string
{
return $this->id;
}
#[ORM\Column(
type : Types::STRING,
enumType: CampaignType::class
)]
private CampaignType $campaignType;
public function getCampaignType(): CampaignType
{
return $this->campaignType;
}
#[ORM\Column(
type : Types::STRING,
nullable: false,
)]
private string $name;
public function getName(): string
{
return $this->name;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private DateTime $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private DateTime $validFrom;
public function getValidFrom(): DateTime
{
return $this->validFrom;
}
public function setValidFrom(DateTime $validFrom): void
{
$this->validFrom = $validFrom;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private DateTime $validUntil;
public function getValidUntil(): DateTime
{
return $this->validUntil;
}
public function setValidUntil(DateTime $validUntil): void
{
$this->validUntil = $validUntil;
}
#[ORM\Column(
type : Types::INTEGER,
nullable: false,
)]
private int $poolSize;
public function getPoolSize(): int
{
return $this->poolSize;
}
public function setPoolSize(int $poolSize): void
{
$this->poolSize = $poolSize;
}
#[ORM\Column(
type : Types::STRING,
nullable: true
)]
private ?string $forRecurrentJobId = null;
public function getForRecurrentJobId(): ?string
{
return $this->forRecurrentJobId;
}
#[ORM\Column(
type : Types::STRING,
nullable: true
)]
private ?string $forCustomerInternalId = null;
public function getForCustomerInternalId(): ?string
{
return $this->forCustomerInternalId;
}
}