<?php

declare(strict_types=1);

namespace App\Domain\Shared\Infrastructure\ApiPlatform\State\Processor;

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Domain\Shared\Application\Command\DeleteJob;
use App\Domain\Shared\Application\CommandHandler\DeleteJobHandler;
use App\Domain\Shared\Domain\Exception\JobNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

readonly class DeleteJobProcessor implements ProcessorInterface
{
    public function __construct(
        private DeleteJobHandler $handler
    ) {
    }

    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
    {
        try {
            $this->handler->handle(new DeleteJob($uriVariables['id']));
        } catch (JobNotFoundException $e) {
            throw new NotFoundHttpException($e->getMessage(), $e);
        }
    }
}
