<?php

namespace App\Controller\OgBoot\PxeTemplate;

use App\Controller\OgDhcp\AbstractOgDhcpController;
use App\Dto\Input\PxeTemplateAddClientsInput;
use App\Dto\Input\PxeTemplateDeleteClientInput;
use App\Entity\Client;
use App\Entity\PxeTemplate;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

#[AsController]
class DeleteClientAction extends AbstractOgDhcpController
{

    /**
     * @throws TransportExceptionInterface
     * @throws ServerExceptionInterface
     * @throws RedirectionExceptionInterface
     * @throws ClientExceptionInterface
     */
    public function __invoke(PxeTemplateDeleteClientInput $input, PxeTemplate $pxeTemplate, HttpClientInterface $httpClient): JsonResponse
    {
        $client = $input->client;

        /** @var Client $clientEntity */
        $clientEntity = $client->getEntity();

        $pxeTemplate->removeClient($clientEntity);

        $this->entityManager->persist($clientEntity);
        $this->entityManager->flush();

        return new JsonResponse(status: Response::HTTP_OK);
    }
}