<?php

namespace AutoAdmin\Bundle\Media\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class MapperConfigPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        $config = $container->getParameter('aa_media_config');
        $mappings = $config['mappings'] ?? [];

        foreach ($mappings as $slug => $mapping) {
            $class = $mapping['class'];
            $definition = $container->getDefinition($class);
            $definition->setArgument('$mapperConfig', $mapping);
        }
    }
}
