<?php

declare(strict_types=1);

namespace App\Entity\Billing;

// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Core\File;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * Fais le lien entre les factures (Bill) concernées par l'export et l'objet File généré
 * NB: BergerLevrault est un format de données demandé par le Trésor Public pour l'export des données comptables.
 */
// #[Auditable]
#[ORM\Entity]
#[ApiResource(operations: [])]
class BergerLevrault
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    /** @var Collection<int, Bill> */
    #[ORM\OneToMany(targetEntity: Bill::class, mappedBy: 'bergerLevrault', cascade: ['persist'], orphanRemoval: true)]
    private Collection $bills;

    #[ORM\OneToOne(targetEntity: File::class, cascade: ['persist'])]
    protected ?File $file;

    public function __construct()
    {
        $this->bills = new ArrayCollection();
    }

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

    /**
     * @return Collection<int, Bill>
     */
    public function getBills(): Collection
    {
        return $this->bills;
    }

    public function addBill(Bill $bill): self
    {
        if (!$this->bills->contains($bill)) {
            $this->bills[] = $bill;
            $bill->setBergerLevrault($this);
        }

        return $this;
    }

    public function removeBill(Bill $bill): self
    {
        if ($this->bills->removeElement($bill)) {
            // set the owning side to null (unless already changed)
            if ($bill->getBergerLevrault() === $this) {
                $bill->setBergerLevrault(null);
            }
        }

        return $this;
    }

    public function getFile(): File
    {
        return $this->file;
    }

    public function setFile(File $file): self
    {
        $this->file = $file;

        return $this;
    }
}
