<?php
declare(strict_types=1);

namespace App\Entity\Billing;

use ApiPlatform\Core\Annotation\ApiResource;
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 BillCredit, et supprimer l'attribut discr.
 *
 * Classe ... qui ...
 */
#[Auditable]
#[ORM\Entity]
#[ORM\Table(name: 'BillAccounting')]
#[ApiResource(
    collectionOperations:[],
    itemOperations: [
        "get" => ["security" => "is_granted('ROLE_ADMIN') and object.getOrganization().getId() == user.getOrganization().getId()"]
    ]
)]
class BillCredit extends BillAccounting implements BillAccountingInterface
{
    #[ORM\Column(length: 255, nullable: false)]
    protected string $discr = 'billcredit';

    #[ORM\ManyToOne(inversedBy: 'billCredits')]
    #[ORM\JoinColumn(nullable: false)]
    protected Access $access;

    public function getAccess(): ?Access
    {
        return $this->access;
    }

    public function setAccess(?Access $access): self
    {
        $this->access = $access;

        return $this;
    }
}