<?php

namespace App\User\Framework\Controller\Api;

use Aimeos\Map;
use App\User\Framework\Repository\PreferencesRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class PreferencesApiController extends AbstractController
{
    #[Route('/api/preferences/media', name: 'api_preferences_media')]
    public function getMediaPreferences(
        PreferencesRepository $preferencesRepository,
    ): Response {
        return $this->json(
            Map::from($preferencesRepository->findEnabled())
                ->rekey(fn($element) => $element->getId())
                ->toArray()
        );
    }
}
