<?php

declare(strict_types=1);

namespace App\Entity\Core;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Entity\Access\Access;
use App\Entity\Organization\Organization;
use App\Repository\Core\NotificationRepository;
// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\ORM\Mapping as ORM;

/**
 * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table Notification, et supprimer l'attribut discr.
 *
 * Notification à un utilisateur
 *
 * Security :
 *
 *   * @see App\Doctrine\Core\CurrentUserNotificationExtension
 */
#[ApiResource(
    operations: [
        new Get(),
        new GetCollection(
            paginationMaximumItemsPerPage: 20,
            paginationClientItemsPerPage: true,
            order: ['id' => 'DESC']
        ),
    ]
)]
// #[Auditable]
#[ORM\Entity(repositoryClass: NotificationRepository::class)]
class Notification extends AbstractInformation
{
    #[ORM\ManyToOne(inversedBy: 'notifications')]
    #[ORM\JoinColumn(nullable: false)]
    protected Access $recipientAccess;

    #[ORM\ManyToOne(inversedBy: 'notifications')]
    #[ORM\JoinColumn(nullable: false)]
    protected Organization $recipientOrganization;

    public function setRecipientAccess(?Access $recipientAccess): self
    {
        $this->recipientAccess = $recipientAccess;

        return $this;
    }

    public function getRecipientAccess(): ?Access
    {
        return $this->recipientAccess;
    }

    public function getRecipientOrganization(): ?Organization
    {
        return $this->recipientOrganization;
    }

    public function setRecipientOrganization(?Organization $recipientOrganization): self
    {
        $this->recipientOrganization = $recipientOrganization;

        return $this;
    }
}
