<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use App\Entity\Constructeur;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Events;

#[AsDoctrineListener(event: Events::onFlush)]
final class ConstructeurAuditSubscriber extends AbstractAuditSubscriber
{
    protected function supports(object $entity): bool
    {
        return $entity instanceof Constructeur;
    }

    protected function entityType(): string
    {
        return 'constructeur';
    }

    protected function snapshotEntity(object $entity): array
    {
        return [
            'id'    => $entity->getId(),
            'name'  => $this->safeGet($entity, 'getName'),
            'email' => $this->safeGet($entity, 'getEmail'),
            'phone' => $this->safeGet($entity, 'getPhone'),
        ];
    }
}
