<?php

namespace NoahVet\Reef\Infrastructure\Http\Post;

use NoahVet\Reef\Application\Port\RequestBodyResolverServiceInterface as SelfInterface;
use NoahVet\Reef\Application\Resolver\RequestBodyResolverInterface;
use NoahVet\Reef\Domain\Serialization\Jane\JaneSerializerFacadeInterface;

class RequestBodyResolverService implements SelfInterface
{
    public function __construct(
        private readonly JaneSerializerFacadeInterface $janeSerializer,
    ) {
    }

    #[\Override]
    public function __invoke(RequestBodyResolverInterface $resolver): array
    {
        $requestDto = $this->janeSerializer->deserialize(
            data: $resolver->requestContent(),
            type: $resolver->janeDtoFQCN(),
        );

        return $this->janeSerializer->normalize(object: $requestDto);
    }
}
