<?php

declare(strict_types=1);

namespace App\Controller\OgAgent;

use App\Dto\Input\GetGitDataInput;
use App\Entity\Client;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class GetGitDataAction extends AbstractOgAgentController
{
    public function __invoke(GetGitDataInput $input): JsonResponse
    {
        $data = [
            'nfn' => 'GetGitData',
            'dsk' => (string) $input->partition->getEntity()->getDiskNumber(),
            'par' => (string) $input->partition->getEntity()->getPartitionNumber(),
        ];


        $response = $this->createRequest(
            method: 'POST',
            url: 'https://'.$input->client->getEntity()->getIp().':8000/opengnsys/GetGitData',
            params: [
                'json' => $data,
            ],
            token: $input->client->getEntity()->getToken(),
        );

        $parsedResponse = [
            'branch' => $response['branch'] ?? null,
            'repo' => $response['repo'] ?? null,
        ];

        return new JsonResponse(data: $parsedResponse, status: Response::HTTP_OK);
    }
}       