<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table('license')]
#[ORM\Entity]
class License implements \JsonSerializable
{
#[ORM\Column('id', 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue('IDENTITY')]
private int $id;
#[ORM\OneToOne(targetEntity: Customer::class, inversedBy: 'license')]
#[ORM\JoinColumn('customer')]
private Customer $customer;
#[ORM\Column('license_date_limit', 'datetime_immutable')]
private ?\DateTimeImmutable $dateLimit;
#[ORM\Column('license_date_start', 'datetime_immutable')]
private ?\DateTimeImmutable $dateStart;
#[ORM\Column('users_limit', 'integer')]
private int $usersLimit = 0;
#[ORM\Column('size_limit', 'integer')]
private int $sizeLimit = 0;
public function __construct(Customer $customer)
{
$this->customer = $customer;
$this->dateStart = new \DateTimeImmutable();
$this->dateLimit = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): License
{
$this->id = $id;
return $this;
}
public function getCustomer(): Customer
{
return $this->customer;
}
public function setCustomer(Customer $customer): License
{
$this->customer = $customer;
return $this;
}
public function getDateLimit(): ?\DateTimeImmutable
{
return $this->dateLimit;
}
public function setDateLimit(?\DateTimeImmutable $dateLimit): License
{
$dateLimit?->setTime(23, 59, 59);
$this->dateLimit = $dateLimit;
return $this;
}
public function getUsersLimit(): int
{
return $this->usersLimit;
}
public function setUsersLimit(?int $usersLimit): License
{
$this->usersLimit = (int)$usersLimit;
return $this;
}
public function getSizeLimit(): int
{
return $this->sizeLimit;
}
public function setSizeLimit(?int $sizeLimit): License
{
$this->sizeLimit = (int)$sizeLimit;
return $this;
}
public function getDateStart(): ?\DateTimeImmutable
{
return $this->dateStart;
}
public function setDateStart(?\DateTimeImmutable $dateStart): License
{
$this->dateStart = $dateStart;
return $this;
}
public function jsonSerialize(): array
{
return [
'dateLimit' => $this->getDateLimit()->format('Y-m-d'),
'dateStart' => $this->dateStart?->format('Y-m-d'),
'sizeLimit' => $this->getSizeLimit(),
'usersLimit' => $this->getUsersLimit(),
'additionalModules' => $this->getCustomer()->getActiveModuleLicense()->toArray(),
];
}
}