<?php

namespace App\Classes\Service\Documents;


class FilterDocuments
{

    /** @var array */
    protected $documents;

    /**
     * FilterDocuments constructor.
     * @param array $documents
     */
    public function __construct(array $documents)
    {
        $this->documents = $documents;
    }

    /**
     * @param string $type
     * @return array
     */
    public function execute(string $type): array {

        return array_filter($this->documents, function($document) use($type) {
            return ($type === 'old') ? substr($document, 0, 5) !== 'data:': substr($document, 0, 5) === 'data:';
        });
    }
}