<?php

namespace Fifa\ConnectId\Sdk\ApiClient;

use Fifa\ConnectServiceBus\Sdk\Utils\ToStringConverter;
use Psr\Log\LoggerInterface;

trait HttpResponseLogging
{
    /**
     * @param LoggerInterface $logger
     * @param mixed $response
     * @param int $statusCode
     * @param array $httpHeaders
     * @param string|null $logMessage
     */
    public function logResponse(LoggerInterface $logger, $response, int $statusCode, array $httpHeaders, string $logMessage = null)
    {
        $logMessage = is_string($logMessage) ? $logMessage : 'Received response from the ID Directory service';

        $logger->debug($logMessage, array(
            'response' => ToStringConverter::mixedToString($response),
            'statusCode' => strval($statusCode),
            'httpHeader' => ToStringConverter::arrayToString($httpHeaders)
        ));
    }
}