<?php
namespace JanusHercules\Clearing\Domain\Entity;
use App\Entity\User;
use App\Utility\DatabaseIdGenerator;
use App\Utility\DateTimeUtility;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Exception;
#[ORM\Entity]
#[ORM\Table(name: 'clearing_request')]
class ClearingRequest
{
public const CLEARING_TYPE_CUSTOMER_RECURRENT_JOBS_DELETION = 0;
public const CLEARING_TYPES_WITH_NAMES = [
self::CLEARING_TYPE_CUSTOMER_RECURRENT_JOBS_DELETION => 'Löschung aller RJs von Customer'
];
/**
* @throws Exception
*/
public function __construct(
User $user,
int $type,
?string $additionalInfo
) {
$this->user = $user;
if (!in_array($type, array_flip(self::CLEARING_TYPES_WITH_NAMES))) {
throw new Exception('Unbekannter Clearing Typ');
}
$this->type = $type;
$this->additionalInfo = $additionalInfo;
$this->createdAt = DateTimeUtility::createDateTimeCet();
}
#[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\ManyToOne(
targetEntity: User::class,
cascade : ['persist']
)]
#[ORM\JoinColumn(
name : 'users_id',
referencedColumnName: 'id',
nullable : false,
onDelete : 'CASCADE'
)]
private User $user;
public function getUser(): User
{
return $this->user;
}
#[ORM\Column(
type : Types::INTEGER,
nullable: false
)]
private int $type;
public function getType(): int
{
return $this->type;
}
#[ORM\Column(
type : Types::STRING,
nullable: true
)]
private ?string $additionalInfo;
public function getAdditionalInfo(): ?string
{
return $this->additionalInfo;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private DateTime $createdAt;
public function setCreatedAt(DateTime $createdAt): void
{
$this->createdAt = $createdAt;
}
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
}