<?php
namespace App\Entity;
use DateTime;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as SA;
/**
* Role
*
* @ORM\Table(name="roles", indexes={@ORM\Index(name="user_id", columns={"user_id", "status"}), @ORM\Index(name="IDX_B192D4EEA76ED395", columns={"user_id"}), @ORM\Index(name="IDX_B192D4EE9B6B5FBA", columns={"account_id"})})
* @ORM\Entity
*/
class Role extends Entity
{
public const ROLES = [
'owner' => 'owner'
];
/**
* @var int
*
* @SA\Ignore
* @ORM\Column(name="id", type="bigint", nullable=false, options={"unsigned"=true})
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @SA\Groups({"read", "list"})
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=255, nullable=false)
* @SA\Groups({"read", "list"})
*/
private $type;
/**
* @var DateTime
*
* @ORM\Column(name="created", type="datetime", nullable=false, options={"default"="CURRENT_TIMESTAMP"})
* @SA\Groups({"read", "list"})
*/
private $created = null;
/**
* @var string
*
* @ORM\Column(name="status", type="string", length=0, nullable=false, options={"default"="inactive"})
* @SA\Ignore()
*/
private $status = self::STATUS['inactive'];
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="User", inversedBy="roles")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
* @SA\Ignore()
*/
private $user;
/**
* @var Account
*
* @ORM\ManyToOne(targetEntity="Account", inversedBy="roles")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="account_id", referencedColumnName="id")
* })
* @SA\Ignore()
*/
private $account;
public function __construct(Account $account, User $user, ?string $type = null, ?string $status = null)
{
$this->created = new DateTime();
$account->addRole($this);
$user->addRole($this);
$this->type = $type ?? self::ROLES['owner'];
$this->status = $status ?? self::STATUS['active'];
}
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getCreated(): ?DateTimeInterface
{
return $this->created;
}
public function setCreated(DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getAccount(): ?Account
{
return $this->account;
}
public function setAccount(?Account $account): self
{
$this->account = $account;
return $this;
}
}