<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\PromocodeRepository;
use App\Traits\UuidEntityTrait;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=PromocodeRepository::class)
* @ORM\Table(indexes={
* @ORM\Index(name="promocode_value", columns={"value"})
* })
*/
class Promocode
{
use UuidEntityTrait;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private string $owner;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private ?string $value = null;
/**
* @ORM\Column(type="integer")
*/
private int $uses = 0;
/**
* @ORM\Column(type="json", options={"default": "{}"})
*/
private array $used = [];
public function __construct(string $email)
{
$this->owner = $email;
}
public function getOwner(): string
{
return $this->owner;
}
public function setOwner(string $owner): self
{
$this->owner = $owner;
return $this;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(string $value): self
{
$this->value = $value;
return $this;
}
public function getUses(): int
{
return $this->uses;
}
public function setUses(int $uses): self
{
$this->uses = $uses;
return $this;
}
public function getUsed(): array
{
return $this->used;
}
public function addUsed(string $used): self
{
if (!\in_array($used, $this->used)) {
$this->used[] = $used;
}
return $this;
}
public function removeUsed(string $used): self
{
if (($key = \array_search($used, $this->used)) !== false) {
unset($this->used[$key]);
}
return $this;
}
}