<?php
namespace Fifa\ConnectId\Sdk\Exception;
use Exception;
use Fifa\ConnectId\Sdk\Model\XmlValidationError;

/**
 * Class XmlSerializationException
 * @package Fifa\ConnectId\Sdk\Exception
 */
class XmlSerializationException extends Exception
{
    /**
     * @var array|XmlValidationError[]
     */
    private $xmlValidationErrors;

    /**
     * @var string
     */
    private $xml;

    /**
     * XmlSerializationException constructor.
     *
     * @param string $message
     * @param XmlValidationError[] $xmlValidationErrors
     * @param string $xml
     */
    public function __construct($message, array $xmlValidationErrors, $xml)
    {
        $this->xmlValidationErrors = $xmlValidationErrors;
        $errorMessage = $message . XmlExceptionHelper::flattenErrorMessages($xmlValidationErrors);
        $this->xml = $xml;
        parent::__construct($errorMessage);
    }

    /**
     * @return array|XmlValidationError[]
     */
    public function getXmlValidationErrors(): array
    {
        return $this->xmlValidationErrors;
    }

    /**
     * @return string
     */
    public function getXml(): string
    {
        return $this->xml;
    }
}