<?php

namespace App\Classes\Modules\Documents\Services;

use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Models\Document;
use App\Models\File;

class CreatesFiles extends AbstractUpdateRelationshipRecord
{
    /**
     * @param Document $document
     * @param DocumentObject $object
     * @return array
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Document $document, DocumentObject $object)
    {
        $models = [];

        foreach ($object->getFiles() as $file) {

            $model = new File(['file' => $file]);
            $models[] = $this->handler($document->files(), $model);

        }

        return $models;

    }
}