<?php

namespace NoahVet\Reef\Plugin\Cache\Model\Factory;

use NoahVet\Reef\Plugin\Cache\Model\CacheableResponse;
use Psr\Http\Message\ResponseInterface;

class CacheableResponseFactory
{
    /**
     * @psalm-suppress ArgumentTypeCoercion
     */
    public function create(ResponseInterface $response): CacheableResponse
    {
        /** @var array<string, list<string>> $headers */
        $headers = $response->getHeaders();

        return new CacheableResponse(
            $response->getProtocolVersion(),
            $response->getStatusCode(),
            $response->getReasonPhrase(),
            $headers,
            $response->getBody(),
        );
    }
}
