<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\InsuredUserRepository;
use App\Trait\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
#[ORM\Entity(repositoryClass: InsuredUserRepository::class)]
#[ApiResource(iri: 'InsuredUser')]
class InsuredUser
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ApiProperty()]
#[Groups([
'user:collection:post',
'user:item:get',
'user:item:put',
])]
#[MaxDepth(1)]
#[ORM\ManyToOne(targetEntity: Insured::class, inversedBy: 'users')]
private $insured;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'insureds', cascade: ["persist"])]
#[Groups([
'insured:item:get',
])]
private $user;
#[ApiProperty()]
#[Groups([
'import:insured',
'insured:item:get',
])]
private $userIdentifier;
#[ApiProperty()]
#[Groups([
'insured:item:get',
])]
private $avatar;
public function getId(): ?int
{
return $this->id;
}
public function getInsured(): ?Insured
{
return $this->insured;
}
public function setInsured(?Insured $insured): self
{
$this->insured = $insured;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getUserIdentifier(): ?string
{
return $this->getUser()->getUserIdentifier();
}
public function getAvatar(): ?string
{
return $this->getUser()->getAvatar() ? $this->getUser()->getAvatar()->getContentUrl() : false;
}
}