<?php
declare (strict_types=1);

namespace App\Entity\Person;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Core\AddressPostal;
use App\Repository\Person\PersonAddressPostalRepository;

//use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Lien entre une Person et une AddressPostal
 */
#[ApiResource(
    operations: [
        new Get(
            security: 'is_granted(\'ROLE_USERS_VIEW\')'
        )
    ]
)]
//#[Auditable]
#[ORM\Entity(repositoryClass: PersonAddressPostalRepository::class)]
class PersonAddressPostal
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'personAddressPostal')]
    #[ORM\JoinColumn(nullable: false)]
    private Person $person;

    #[ORM\OneToOne(inversedBy: 'personAddressPostal', cascade: ['persist', 'remove'])]
    #[ORM\JoinColumn(nullable: false)]
    #[Groups("access_address")]
    private AddressPostal $addressPostal;

    #[ORM\Column(length: 255)]
    #[Assert\Choice(callback: ['\\App\\Enum\\Person\\AddressPostalPersonTypeEnum', 'toArray'], message: 'invalid-address-postal-type')]
    #[Groups("access_address")]
    private string $type;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getPerson(): ?Person
    {
        return $this->person;
    }

    public function setPerson(?Person $person): self
    {
        $this->person = $person;
        return $this;
    }

    public function getAddressPostal(): ?AddressPostal
    {
        return $this->addressPostal;
    }

    public function setAddressPostal(AddressPostal $addressPostal): self
    {
        $this->addressPostal = $addressPostal;
        return $this;
    }

    public function getType(): string
    {
        return $this->type;
    }

    public function setType(string $type): self
    {
        $this->type = $type;
        return $this;
    }
}
