<?php

namespace App\Classes\Modules\Documents\Services;

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

class CreatesDocument extends AbstractUpdateRelationshipRecord
{
    /**
     * @param Documentable $documentable
     * @param DocumentObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Documentable $documentable, DocumentObject $object)
    {
        $model = new Document();
        $model->document_type = $object->getDocumentType();
        $model->reference = $object->getReference();

        return $this->handler($documentable->documents(), $model);
    }
}