<?php

namespace App\Classes\Modules\Companies\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyModuleObject;
use App\Models\Company;
use App\Models\CompanyModule;

class CreatesCompanyModule extends AbstractUpdateRelationshipRecord
{

    /**
     * @param Company $company
     * @param CompanyModuleObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Company $company, CompanyModuleObject $object)
    {
        $model = new CompanyModule();
        $model->name = $object->getName();
        $model->reference = $object->getReference();
        $model->type = $object->getType();
        $model->status = $object->getStatus();
        $model->unity_hash_id = $object->getUnityHashId();
        $model->unity_signature = $object->getUnitySignature();

        return $this->handler($company->companyModules(), $model);
    }
}
