<?php

declare(strict_types=1);

namespace App\SignDocument\Controller;

use App\SignDocument\Api\Request\SignRequest;
use App\SignDocument\Services\SignService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class SignController extends AbstractController
{
    public function __construct(
        private readonly SignService $signService
    ){
    }

    #[Route(path: '/sign', name: 'app.sign',  methods: ['POST'])]
    public function __invoke(Request $request, SignRequest $signRequest): Response
    {
        $token = $request->server->get('HTTP_AUTHORIZATION');

        return new JsonResponse($this->signService->signDocument($signRequest, $token));
    }
}