<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\PersonBundle\PersonIdentifier\Normalizer;

use Chill\PersonBundle\PersonIdentifier\PersonIdentifierWorker;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

final readonly class PersonIdentifierWorkerNormalizer implements NormalizerInterface
{
    public function normalize($object, ?string $format = null, array $context = []): array
    {
        if (!$object instanceof PersonIdentifierWorker) {
            throw new \Symfony\Component\Serializer\Exception\UnexpectedValueException();
        }

        return [
            'type' => 'person_identifier_worker',
            'definition_id' => $object->getDefinition()->getId(),
            'engine' => $object->getDefinition()->getEngine(),
            'label' => $object->getDefinition()->getLabel(),
            'isActive' => $object->getDefinition()->isActive(),
            'presence' => $object->getDefinition()->getPresence()->value,
        ];
    }

    public function supportsNormalization($data, ?string $format = null): bool
    {
        return $data instanceof PersonIdentifierWorker;
    }
}
