<?php

declare(strict_types=1);

namespace App\SignDocument\Controller;

use App\Infrastructure\Traits\ApiHelperTrait;
use App\SignDocument\Api\Request\DigitalSignatureRequest;
use App\SignDocument\Services\DigitalSignatureService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DigitalSignatureController extends AbstractController
{
    use ApiHelperTrait;
    public function __construct(
        private readonly DigitalSignatureService $digitalSignatureService
    ){
    }

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

        return $this->createJsonResponseFromObject(
            $this->digitalSignatureService->getSignature($digitalSignatureRequest, $token)
        );
    }
}