<?php

declare(strict_types=1);

namespace App\Entity\Person;

use ApiPlatform\Metadata\ApiResource;
use App\Entity\Core\AddressPostal;
use App\Entity\Traits\CreatedOnAndByTrait;
use App\Enum\Person\AddressPostalPersonTypeEnum;
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;

/**
 * Lien entre une Person et une AddressPostal.
 */
#[ApiResource(operations: [])]
// #[Auditable]
#[ORM\Entity(repositoryClass: PersonAddressPostalRepository::class)]
class PersonAddressPostal
{
    use CreatedOnAndByTrait;

    #[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'], orphanRemoval: true)]
    #[ORM\JoinColumn(nullable: false)]
    #[Groups('access_address')]
    private AddressPostal $addressPostal;

    #[ORM\Column(length: 50, enumType: AddressPostalPersonTypeEnum::class)]
    #[Groups('access_address')]
    private AddressPostalPersonTypeEnum $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(): AddressPostalPersonTypeEnum
    {
        return $this->type;
    }

    public function setType(AddressPostalPersonTypeEnum $type): self
    {
        $this->type = $type;

        return $this;
    }
}
