<?php

declare (strict_types=1);

namespace App\Entity\Billing;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\Billing\AccessPayerRepository;
use App\Entity\Access\Access;
//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 AccessPayer, et supprimer l'attribut discr.
 *
 * Fais le lien entre l'Access qui règle la facture et l'Access concerné
 *
 */
#[ApiResource(
    operations: [
        new Get(
            security: 'is_granted(\'ROLE_ADMIN\') and object.getAccessPayer().getOrganization().getId() == user.getOrganization().getId()'
        )
    ]
)]
//#[Auditable]
#[ORM\Table(name: 'BillingPayer')]
#[ORM\Entity(repositoryClass: AccessPayerRepository::class)]
class AccessPayer extends AbstractBillingPayer
{
    #[ORM\Column(length: 255, nullable: false)]
    private string $discr = 'access';

    #[ORM\ManyToOne(inversedBy: 'billingPayers')]
    private ?Access $accessPayer = null;

    #[ORM\ManyToOne(inversedBy: 'billingReceivers')]
    private ?Access $accessReceiver = null;

    public function setAccessPayer(?Access $accessPayer): self
    {
        $this->accessPayer = $accessPayer;
        return $this;
    }

    public function getAccessPayer(): ?Access
    {
        return $this->accessPayer;
    }

    public function setAccessReceiver(?Access $accessReceiver): self
    {
        $this->accessReceiver = $accessReceiver;
        return $this;
    }

    public function getAccessReceiver(): ?Access
    {
        return $this->accessReceiver;
    }
}
