<?php

declare(strict_types=1);

namespace App\Module\Integration\Infrastructure\Controller;

use App\Module\Integration\Domain\Repository\ShareConfigurationRepositoryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class ShareStatusController extends AbstractController
{
    public function __construct(
        private readonly ShareConfigurationRepositoryInterface $configRepository,
    ) {}

    #[Route('/api/share/status', name: 'share_status', methods: ['GET'], priority: 1)]
    #[IsGranted('ROLE_USER')]
    public function __invoke(): JsonResponse
    {
        $config = $this->configRepository->findSingleton();

        return new JsonResponse(['enabled' => null !== $config && $config->isUsable()]);
    }
}
