<?php

declare(strict_types=1);

namespace App\EventSubscriber;

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

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

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

    protected function snapshotEntity(object $entity): array
    {
        return [
            'id'          => $entity->getId(),
            'name'        => $this->safeGet($entity, 'getName'),
            'code'        => $this->safeGet($entity, 'getCode'),
            'category'    => $this->safeGet($entity, 'getCategory')?->value,
            'notes'       => $this->safeGet($entity, 'getNotes'),
            'description' => $this->safeGet($entity, 'getDescription'),
        ];
    }
}
