<?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\OrderRoleObject;
use App\Models\CompanyModule;
use App\Models\Order;
use App\Models\OrderRole;

class CreatesOrderRole extends AbstractUpdateRelationshipRecord
{

    /**
     * @param OrderRoleObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(OrderRoleObject $object)
    {
        $model = new OrderRole();
        $model->role_id = $object->getRole();
        $model->company_module_id = $object->getCompanyModule()->id;

        return $this->handler($object->getOrder()->OrderRoles(), $model);
    }
}
