<?php

declare(strict_types=1);

namespace App\Entity\Message;

use ApiPlatform\Metadata\ApiResource;
// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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 Email, et supprimer l'attribut discr.
 * @todo : migration table tag_message
 *
 * Email
 */
// #[Auditable]
#[ApiResource(operations: [])]
#[ORM\Entity]
class Email extends AbstractMessage
{
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    private bool $isSystem = false;

    /** @var Collection<int, ReportEmail> */
    #[ORM\OneToMany(targetEntity: ReportEmail::class, mappedBy: 'email', cascade: ['persist'], orphanRemoval: true)]
    #[ORM\JoinColumn(onDelete: 'cascade')]
    private Collection $reports;

    #[ORM\ManyToOne(cascade: ['persist'])]
    #[ORM\JoinColumn(nullable: true)]
    private ?Mail $mailAttached = null;

    public function __construct()
    {
        $this->reports = new ArrayCollection();
        parent::__construct();
    }

    public function setIsSystem(bool $isSystem): self
    {
        $this->isSystem = $isSystem;

        return $this;
    }

    public function getIsSystem(): bool
    {
        return $this->isSystem;
    }

    /**
     * @return Collection<int, ReportEmail>
     */
    public function getReports(): Collection
    {
        return $this->reports;
    }

    public function addReport(ReportEmail $report): self
    {
        if (!$this->reports->contains($report)) {
            $this->reports[] = $report;
            $report->setEmail($this);
        }

        return $this;
    }

    public function removeReport(ReportEmail $report): self
    {
        if ($this->reports->removeElement($report)) {
            // set the owning side to null (unless already changed)
            if ($report->getEmail() === $this) {
                $report->setEmail(null);
            }
        }

        return $this;
    }

    public function getMailAttached(): ?Mail
    {
        return $this->mailAttached;
    }

    public function setMailAttached(?Mail $mailAttached): self
    {
        $this->mailAttached = $mailAttached;

        return $this;
    }
}
