<?php
namespace JanusHercules\Jobradar\Domain\Entity;
use App\Entity\RecurrentJob;
use App\Entity\WantedJob;
use App\Utility\DatabaseIdGenerator;
use App\Utility\DateTimeUtility;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\CustomIdGenerator;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Exception;
#[Entity]
#[Table(
name : 'jobradar_matches',
uniqueConstraints: [
new UniqueConstraint(name: 'idx_wanted_jobs_id_recurrent_jobs_id', columns: ['wanted_jobs_id', 'recurrent_jobs_id'])
]
)]
class JobradarMatch
{
#[Id]
#[GeneratedValue(strategy: 'CUSTOM')]
#[CustomIdGenerator(class: DatabaseIdGenerator::class)]
#[Column(
type : Types::GUID,
unique: true
)]
private string $id;
#[Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private DateTime $createdAt;
#[Column(
type : Types::BOOLEAN,
nullable: false
)]
private bool $isPinned = false;
#[Column(
type : Types::BOOLEAN,
nullable: false
)]
private bool $isRead = false;
#[Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private ?DateTime $pinnedAt = null;
#[Column(
type : Types::BOOLEAN,
nullable: false
)]
private bool $isDeleted = false;
#[ManyToOne(
targetEntity: WantedJob::class,
cascade : ['persist']
)]
#[JoinColumn(
name : 'wanted_jobs_id',
referencedColumnName: 'id',
nullable : false,
onDelete : 'CASCADE'
)]
private WantedJob $wantedJob;
#[ManyToOne(
targetEntity: RecurrentJob::class,
cascade : ['persist']
)]
#[JoinColumn(
name : 'recurrent_jobs_id',
referencedColumnName: 'id',
nullable : false,
onDelete : 'CASCADE'
)]
private RecurrentJob $recurrentJob;
/**
* @throws Exception
*/
public function __construct(
RecurrentJob $recurrentJob,
WantedJob $wantedJob,
) {
$this->createdAt = DateTimeUtility::createDateTimeUtc();
$this->recurrentJob = $recurrentJob;
$this->wantedJob = $wantedJob;
}
public function getId(): string
{
return $this->id;
}
public function setId(string $id): void
{
$this->id = $id;
}
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
public function setCreatedAt(DateTime $createdAt): void
{
$this->createdAt = $createdAt;
}
public function isPinned(): bool
{
return $this->isPinned;
}
public function setIsPinned(bool $isPinned): void
{
$this->isPinned = $isPinned;
}
public function isRead(): bool
{
return $this->isRead;
}
public function setIsRead(bool $isRead): void
{
$this->isRead = $isRead;
}
public function getPinnedAt(): ?DateTime
{
return $this->pinnedAt;
}
public function setPinnedAt(?DateTime $pinnedAt): void
{
$this->pinnedAt = $pinnedAt;
}
public function isDeleted(): bool
{
return $this->isDeleted;
}
public function setIsDeleted(bool $isDeleted): void
{
$this->isDeleted = $isDeleted;
}
public function getWantedJob(): WantedJob
{
return $this->wantedJob;
}
public function getRecurrentJob(): RecurrentJob
{
return $this->recurrentJob;
}
}