<?php

namespace App\Classes\Modules\Accounts\Services;


use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject;
use App\Classes\ValueObjects\Constants\Roles;
use App\Models\User;
use Illuminate\Support\Facades\Hash;

class CreatesUser extends AbstractUpdateRecord
{

    /**
     * @param RegistrationObject $object
     * @return \Illuminate\Database\Eloquent\Model|null
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(RegistrationObject $object){
        $model = new User();
        $model->email = $object->getEmail();
        $model->name = $object->getName();
        $model->password = Hash::make($object->getPassword());
        $model->role_id = Roles::USER;

        return $this->handler($model);
    }

}