<?php

namespace NoahVet\Reef\RabbitMQ\Serializer\Normalizer;

use NoahVet\Reef\RabbitMQ\Task\ConsoleCommandTask;
use NoahVet\Reef\RabbitMQ\Task\NamedCommandTask;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class NamedCommandTaskNormalizer implements NormalizerInterface
{
    /**
     * @return array<class-string|'*'|'object'|string, bool|null>
     */
    public function getSupportedTypes(?string $format): array
    {
        return [
            NamedCommandTask::class => true,
        ];
    }

    /**
     * @return array{type: string, command: string|null, arguments: array<string, string|int>}
     */
    #[\Override]
    public function normalize($object, ?string $format = null, array $context = []): array
    {
        \assert($object instanceof NamedCommandTask);

        return [
            'type' => ConsoleCommandTask::class,
            'command' => $object->commandName,
            'arguments' => $object->arguments,
        ];
    }

    /**
     * @param array<mixed> $context
     */
    #[\Override]
    public function supportsNormalization($data, ?string $format = null, array $context = []): bool
    {
        return $data instanceof NamedCommandTask;
    }
}
