<?php

namespace App\Classes\Modules\Orders\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
use App\Models\CompanyModule;
use App\Models\Order;

class CreatesOrder extends AbstractUpdateRelationshipRecord
{

    /**
     * @param CompanyModule $companyModule
     * @param OrderObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(CompanyModule $companyModule, OrderObject $object)
    {
        $model = new Order();
        $model->reference = $object->getReference();
        $model->type = $object->getType();
        $model->status = $object->getStatus();

        return $this->handler($companyModule->orders(), $model);
    }
}
