<?php


namespace Fifa\ConnectId\Sdk\Model\Validation;


class PdfValidator implements DocumentValidatorInterface
{
    /**
     * @param string $base64Content
     * @return DocumentValidationResult
     */
    public function validate(string $base64Content): DocumentValidationResult
    {
        $validationResult = new DocumentValidationResult();
        $decoded = base64_decode($base64Content);

        if (!preg_match("/^%PDF-/", $decoded)) {
            return $validationResult->failed('Document is not a valid UTF-8 formatted PDF.');
        }

        return $validationResult;
    }
}